i got for example results like that
user1
user1
user2
user1
user1
user3
user1
i want to limit user1 to have maximum 4 resilts ,if user1 have 5 results it will be deleted ,this is example of code that im trying to build:
what i need is to delete the oldest record from the specific user ,but it is not doing that!! ,please help!
thanx in advanced.
user1
user1
user2
user1
user1
user3
user1
i want to limit user1 to have maximum 4 resilts ,if user1 have 5 results it will be deleted ,this is example of code that im trying to build:
Code:
<?
$query = mysql_query("SELECT * FROM `my_table` where username='$username' ") or die(mysql_error());
$last = '';
$count = 0;
while($line = mysql_fetch_assoc($query)) {
if($last == $line['username']) $count++;
else {
$last = $line['username'];
$count = 1;
}
if($count > 4) {
$sql_delete="DELETE FROM my_table WHERE username = '$username'";
mysql_query($sql_delete)or die(mysql_error());
}
}
?>
thanx in advanced.
Comment