So, you are saying that, in order to get an ordered list out, I need to retrieve the data by basically sorting it using an 'order by' statement? I understand what you are saying, but, how would I do this then? Here is the entire display script:
<?php
session_start();
include 'include/config.php';
echo '<head>';
echo '<meta http-equiv="refresh" content="10">';
echo '</head>';
$chatroom=$_SESSION['chatroom'];
$query = "SELECT * FROM chat";
$result = mysql_query($query) or exit(mysql_error());
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
if($row['chatroom'] == $chatroom)
{
$cname=$row['uname'];
$mess=$row['message'];
echo '<b style="color:#FF0000">' . $cname . '</b> : ' . $mess;
echo '<br>';
}
}
// Now we need to perform housecleaning function - check for older messages and delet if older than certain time frame from now.
$timenow=time();
$query = "SELECT * FROM chat";
$result = mysql_query($query) or exit(mysql_error());
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$messnow=$row['timestamp'];
$timediff=($timenow) - $row['timestamp'];
if($timediff > "1200")
{
$query1="DELETE FROM chat WHERE timestamp='$messnow' LIMIT 1";
$result1 = mysql_query($query1) or exit(mysql_error());
}
}
It displays the data one record at a time, since the amounts of records in the particular table changes. The display script also checks for outdated data and deletes it if the data is older than a certain time frame. This seems to work excellently. However, I guess my question is, since I dont know how much data is in the table at any certain time, how do I read it back in order when I am reading one record at a time, displaying it, then going back for more? Is the a more efficient way to do this?
Ice