...

View Full Version : readmore link



rjkdonaldson
03-10-2010, 06:23 AM
Hello,

I'm trying to figure out how to make a readmore link to show the full length of a message I have worked out the php part by using substr and now want to make it so that when the read more link is clicked the full message will be diplayed on the same page. Can someone help me out? The area I'm having trouble with is the linking part <a href=message_board.php> I'm not sure what to append to the end of the file. I'll post the code to the page I'm working on if need be. I've posted the entire page.



<?php # modified script (sort disabled) - classifieds.php
# (modified 12 Jan 2009)

// This script retrieves all the records from the users table.
// This new version allows the results to be sorted in different ways.




require_once ('mysql_connect.php'); // Connect to the db.


// Number of records to show per page:
$display = 10;

// Determine how many pages there are.
if (isset($_GET['np'])) { // Already been determined.
$num_pages = $_GET['np'];
} else { // Need to determine.

// Count the number of records
$query = "SELECT COUNT(*) FROM entry ORDER BY id ASC";
$result = mysql_query ($query);
$row = mysql_fetch_array ($result, MYSQL_NUM);
$num_records = $row[0];

// Calculate the number of pages.
if ($num_records > $display) { // More than 1 page.
$num_pages = ceil ($num_records/$display);
} else {
$num_pages = 1;
}

} // End of np IF.

// Determine where in the database to start returning results.
if (isset($_GET['s'])) {
$start = $_GET['s'];
} else {
$start = 0;
}



// Make the query.
$query = "SELECT * from entry LIMIT $start, $display";
$result = mysql_query ($query); // Run the query.

// Fetch and print all the records.


echo '<center><table style="width:100%; border:1px solid #000000;"><span style="color:#800000;font-size:18px";><center>Affirmation Board</center></span>
</br>
<tr><th colspan=\"4\"></th></tr>';

while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$id = $row['id'];
$message = nl2br(substr($row['message'],0,200));
$name = $row['name'];
$date = $row['date'];
//$readmore = $row['<a href="#">Readmore</a>'];
//nl2br(substr($row[post],0,200)). '<br /><br /><br />';

printf("<tr>

<td>$message</td>
<td>
$name
</td>
<td>$date</td>

<td>

</td></tr><td> <a href='#'>Readmore</a> </td>", $date, $message, $name);



}

print '</table></center>';




mysql_free_result ($result); // Free up the resources.

mysql_close(); // Close the database connection.


// Make the links to other pages, if necessary.
if ($num_pages > 1) {

echo '<center><p>';
// Determine what page the script is on.
$current_page = ($start/$display) + 1;

// If it's not the first page, make a Previous button.
if ($current_page != 1) {
echo '<a href="message_board.php?s=' . ($start - $display) . '&np=' . $num_pages . '">Previous</a> ';
}

// Make all the numbered pages.
for ($i = 1; $i <= $num_pages; $i++) {
if ($i != $current_page) {
echo '<a href="message_board.php?s=' . (($display * ($i - 1))) . '&np=' . $num_pages . '">' . $i . '</a> ';
} else {
echo $i . ' ';
}
}

// If it's not the last page, make a Next button.
if ($current_page != $num_pages) {
echo '<a href="message_board.php?s=' . ($start + $display) . '&np=' . $num_pages . '">Next</a>';
}

echo '</p>';

} // End of links section.




?>

mlseim
03-10-2010, 12:33 PM
Try this ...



$id = $row['id'];
// $message = nl2br(substr($row['message'],0,200));
$message = $row['message'];
$name = $row['name'];
$date = $row['date'];
//$readmore = $row['<a href="#">Readmore</a>'];
//nl2br(substr($row[post],0,200)). '<br /><br /><br />';

rjkdonaldson
03-10-2010, 09:36 PM
Wouldn't that return everything within the message table, what I trying to do is limit the view of what can be seen by the user and then when the readmore link is clicked the entire message will be displayed. I remember that my code was originally
$message = $row['message']; before adding the substr method.

mlseim
03-10-2010, 10:52 PM
oh ... I'm sorry,
I thought it was the other way around.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum