non sono un portento in mysql ma andando a logica potresti provare una cosa del genere:
Codice PHP:
<?php
addtochat($uid, $rid);
$timeto = 300;
$timenw = time();
$timeout = $timenw-$timeto;
$tot_records = mysql_query("SELECT COUNT(*) AS totale FROM ibwf_chat") or die(mysql_error()); //Restituisce il numero di records presenti nella tabella
$row = mysql_fetch_assoc($tot_records); //inserisco il valore nella variabile $row
if ($row['totale'] > 20) // SE ci sono più di 20 record, allora procedo con l'eliminazione
{
$deleted = mysql_query("DELETE FROM ibwf_chat WHERE timesent<".$timeout."");
}
$rooms = mysql_fetch_array(mysql_query("SELECT id, name FROM ibwf_rooms WHERE id='".$rid."'"));
$rname = $rooms[1];
$nick = getnick_sid($sid);
?>
Ciao