PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hi There,
Im very much a mysql php newbie, i have started writting a script which people can post messages on similar to a bulliten board. what i would like to do is have a maximum of 200 posts and when this figure is reached the oldest posts are deleted so there will always be 200 hundred posts.
i see mysql has a delete function but i am not sure how to use this. in my table i have
id
timestamp
message
I would really love some help with this as im sure you guys have the answer.
<?php
$num = mysql_num_rows(mysql_query("select id from table limit 201"));//no need to grab 4000 records when we only need to check for > 200 rows
if($num >= 200)
{
//delete 20 posts
mysql_query("DELETE from table order by id ASC limit 20");
}
?>
Ok 1 thing i dont get.
$num = mysql_num_rows(mysql_query("select id from table limit 201"));
does the above code say check the first 201 roms or the rows with id 201 and below. Just if it does the latter then pretty soon it will be invalid because all the records with id 201 and below will of been deleted, because the number will keep incrementing.
Have i completely missed the point?