...

View Full Version : Grrr sql rage



fus10n
04-24-2012, 09:51 PM
Okay, so the first portion of the code works where it deletes all rows where used = 1 however the else statement where if there are no rows where used = 1 doesn't work...any ideas???????



<?php
$con = mysql_connect("**","**","**");
mysql_select_db("**");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_query("DELETE FROM urls WHERE used='1'") or die(mysql_error());

if (mysql_affected_rows())
{
//Rows were deleted
}
else
{
//No rows deleted so do some deleting
mysql_query("DELETE FROM urls ORDER BY id asc LIMIT 10") or die(mysql_error());
}
?>

tangoforce
04-24-2012, 10:30 PM
Works fine this end. I ran your code (using a different table name) to empty out my log_archive table:



mysql_query("DELETE FROM log_archive WHERE id>'50'") or die(mysql_error());

if (mysql_affected_rows())
{
//Rows were deleted
print 'deleted';
}
else
{
//No rows deleted so do some deleting
mysql_query("DELETE FROM log_archive ORDER BY id asc LIMIT 10") or die(mysql_error());
print 'not deleted';
}


Took me 5 button clicks to delete the final 50 items so I can only say that your code works.

Are you sure you're on the right server? (Easy to run on one and then look at the database on another - eg localhost and the remote server).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum