DELETING PAST SQL DATA with php
Hello
I have a chat program that I would like to delete the oldest chat after 5 chats. So that only the 5 recent chats appear and anything after 5 is deleted. Thank you. This in the code.
//Quering database
$id=$_SESSION['id'];
$collect=mysql_query("SELECT * FROM chats WHERE userid='$id'");
$collectnum=mysql_num_rows($collect);
if($collectnum>5)
{
//delete old chats if user has more than 5 chats
$delete=mysql_query("DELETE * FROM chats WHERE userid='$id' ORDER BY ASC LIMIT 1");
//I hoped the above code would delete the oldest chat in the database for the user but after the 5 chat the delete function does not work as intended.
ASC in the code hopes to delete things in assending order making the fifth chat be deleted first.
//My problem is that the above code does not work.
}
else
{
while(rows=mysql_fetch_assoc($collect))
{
//All CHATS OF THE INDIVIDUAL USER.
}
}
