How would I go about deleting say 10 rows from mysql db where that have the least id value, or the highest id value...or just the first 10 or last 10 rows...thanks in advance
Untested script ... not sure if this will work correctly or not, but it might be enough to get you started ...
PHP Code:
<?php
//choices
// 1= the least 10
// 2= the most 10
// 3= 10 from the top and 10 from the bottom
// pick the choice.
$choice=1;
// connect to your database here
if($choice==1){
$query="SELECT * FROM urls ORDER BY id DESC LIMIT 0,10";
}
if($choice==2){
$query="SELECT * FROM urls ORDER BY id ASC LIMIT 0,10";
}
if($choice==3){
$query="SELECT * FROM urls ORDER BY id DESC LIMIT 0,10 UNION SELECT * FROM urls ORDER BY id ASC LIMIT 0,10 UNION ORDER BY id ASC";
}
Okay, This is what it echos: Resource id #2, meanwhile the smallest id in the table is 40392
PHP Code:
<?php $con = mysql_connect("localhost","*****","*****"); mysql_select_db("dubstep3_project1"); if (!$con) { die('Could not connect: ' . mysql_error()); }
//choices // 1= the least 10 // 2= the most 10 // 3= 10 from the top and 10 from the bottom // pick the choice. $choice=1;
// connect to your database here
if($choice==1){ $query= mysql_query("SELECT * FROM urls ORDER BY id DESC LIMIT 0,10"); } if($choice==2){ $query= mysql_query("SELECT * FROM urls ORDER BY id ASC LIMIT 0,10"); } if($choice==3){ $query= mysql_query("SELECT * FROM urls ORDER BY id DESC LIMIT 0,10 UNION SELECT * FROM urls ORDER BY id ASC LIMIT 0,10 UNION ORDER BY id ASC"); }
I changed it again and now it echos: ArrayArrayArrayArrayArrayArrayArrayArrayArrayArray
PHP Code:
<?php $con = mysql_connect("localhost","******","******"); mysql_select_db("dubstep3_project1"); if (!$con) { die('Could not connect: ' . mysql_error()); }
//choices // 1= the least 10 // 2= the most 10 // 3= 10 from the top and 10 from the bottom // pick the choice. $choice=1;
// connect to your database here
if($choice==1){ $query1= mysql_query("SELECT * FROM urls ORDER BY id DESC LIMIT 0,10"); } if($choice==2){ $query2= mysql_query("SELECT * FROM urls ORDER BY id ASC LIMIT 0,10"); } if($choice==3){ $query3= mysql_query("SELECT * FROM urls ORDER BY id DESC LIMIT 0,10 UNION SELECT * FROM urls ORDER BY id ASC LIMIT 0,10 UNION ORDER BY id ASC"); } while ($res = mysql_fetch_array($query1))