View Single Post
Old 02-16-2010, 04:08 PM   #1 (permalink)
CΛSTΞX
The Acquainted
 
Join Date: Feb 2008
Posts: 107
Thanks: 3
CΛSTΞX is on a distinguished road
Arrow Delete rows except last added 250 ones

Hello mates,

I want to delete all rows in a table except last added 250 ones. I have this script, but it deletes all rows except first 250 ones. I need your help, thanks.

PHP Code:
$query="SELECT * FROM looks";

    
$result=mysql_query($query);
    echo 
mysql_error();

    
$all_looks = array();

    for(
$i=0$i<mysql_num_rows($result); $i++){
        
$row mysql_fetch_array($result);

        
$all_looks[$i] = $row["id"];
    }

    for(
$i=0$i<count($all_looks)-251$i++){
         
mysql_query("DELETE FROM looks WHERE id='".$all_looks[$i]."';");
    }

    echo 
mysql_error(); 
__________________
Downloadic
infolizer
Send a message via MSN to CΛSTΞX
CΛSTΞX is offline  
Reply With Quote