Deleting Data each 24 hours in Database with PHP and MYSQLi -


i know how this:

i have made sort of chatbox automatic updates self script , loads latest 50 chat messages database.

now wonder, how delete messages after each 24 hours keep first new 50 messages , delete older ones after that.

is possible mysqli , php or must better solution?

update

followed advise lund , fast response provider: not able cron jobs or mysql events current plan. not have money upgrading it, erm.... if there solution, thank helping me out on matter folks.


i have table called: chatbox , have in it:

c_id chattext name date 

pseudo code (won't work without edits fit code, idea) - don't know how data stored, or variable names. or table name. or information need work.

$sql = ("select * chatlog order timeadded desc"); //order descending should show newest ones first.  $index = 1; //set index loop through  while($row = mysqli_query($con, $sql) { //use while loop go through table      if($index <= 50) { //for first 50 records         //do nothing     } else { //for after 50 records         $chatid = $row['chatlogid']; //id or unique value actual message.         $sql = ("delete chatlog chatlogid='$chatid'"); //delete table         mysqli_query($con, $sql);//execute query.     }  } 

you can set execute everytime message stored, or check against current time of server remove daily.

update: code should working code

$sql = ("select * chatbox order time desc"); //order descending should show newest ones first.  $index = 1; //set index loop through  while($row = mysqli_query($con, $sql) { //use while loop go through table      if($index <= 50) { //for first 50 records         //do nothing     } else { //for after 50 records         $chatid = $row['c_id']; //id or unique value actual message.         $sql = ("delete chatbox c_id='$chatid'"); //delete table         mysqli_query($con, $sql);//execute query.     }  } 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -