cordoprod Posted May 2, 2008 Share Posted May 2, 2008 Hi. I develope a community system and i have a table called last_visitors.. The structure goes like this: user - visitor - time Lets say there is a row: glenn - frank - (timestamp from time(); ) And when i have like 10 rows where the user is glenn automatically delete the oldest row.. (e.g find that from time col) Do you know how to do that? Link to comment https://forums.phpfreaks.com/topic/103866-delete-row-automatically-when-mysql_num_rows-x/ Share on other sites More sharing options...
cordoprod Posted May 2, 2008 Author Share Posted May 2, 2008 Need help Link to comment https://forums.phpfreaks.com/topic/103866-delete-row-automatically-when-mysql_num_rows-x/#findComment-531704 Share on other sites More sharing options...
darkfreaks Posted May 2, 2008 Share Posted May 2, 2008 <?php $time= time(); $sql=mysql_query( "INSERT INTO table values (user,time)"); while($row=mysql_fetch_array($sql)) { if($row['time']>=15778463) { // deletes user if user time is greater than say 6 months $sql=mysql_query"(DELETE FROM table VALUES (user,time)"); } } ?> Link to comment https://forums.phpfreaks.com/topic/103866-delete-row-automatically-when-mysql_num_rows-x/#findComment-531730 Share on other sites More sharing options...
bbaker Posted May 2, 2008 Share Posted May 2, 2008 <?php $sql = mysql_fetch_array(mysql_query("SELECT COUNT(user) as numusers, MIN(time) as oldest FROM last_visitors")); if ($sql['numusers'] == 10){ mysql_query("DELETE FROM last_visitors WHERE time = '$sql[oldest]'") or die(mysql_error()); } $sql = mysql_query("INSERT INTO last_visitors VALUES ('$guestname','$visitorname','$time')") or die(mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/103866-delete-row-automatically-when-mysql_num_rows-x/#findComment-531760 Share on other sites More sharing options...
cordoprod Posted May 2, 2008 Author Share Posted May 2, 2008 I'll try them out and let you know if i figured it out. =) Link to comment https://forums.phpfreaks.com/topic/103866-delete-row-automatically-when-mysql_num_rows-x/#findComment-531785 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.