Jump to content

Show all/Show 10 records in a shoutbox


jakeoh

Recommended Posts

Hi,

 

I added a shout box to my website after following a tutorial I found on the net. However there is a problem; the shoutbox displays all messages, so in the end it will end up being way too big.

 

I would like to display 10 records (messages), for example, and then add a "View all" link at the bottom of the 10 messages; when a user would click on this link, the rest of the messages would be displayed, but in a given area and scroll bars would be used in order to see all messages.

 

Do you have any idea how this could be done? I am quite new at PHP and MySQL.

 

Here's the code for the page that displays the messages:

 

<?

include("Include/shoutbox_connect.php");

open_connection();

 

$shout_query = "SELECT * FROM shoutbox ORDER BY `date` DESC";

$shout_result = mysql_query($shout_query);

$count = 0;

 

while($shout_row = mysql_fetch_array($shout_result))

{

$shouter_name = $shout_row['username'];

$shout_content = $shout_row['content'];

$shout_content = stripslashes($shout_content);

$shout_date = $shout_row['date'];

 

$dday = substr($shout_date, 8, 2);

$dmonth = substr($shout_date, 5, 2);

$dyear = substr($shout_date, 0, 4);

 

if(($count % 2) != 0)

{

echo "<p class='odd'>$shouter_name - $shout_content - $dday-$dmonth-$dyear</p>";

 

}

else

{

echo "<p class='even'>$shouter_name - $shout_content - $dday-$dmonth-$dyear</p>";

 

}

$count++;

}

 

?>

Link to comment
https://forums.phpfreaks.com/topic/72544-show-allshow-10-records-in-a-shoutbox/
Share on other sites

Thanks!

 

So I'm halfway there. How can I get the user to click on a link so that he can see all comments that have been posted so far?

 

I guess I would use the same query as before, but I can make it so that all these comments are contained within a certain height, with scroll bars if necessary?

 

Thanks again!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.