Click to See Complete Forum and Search --> : deleting MySQL rows


nuthead
11-23-2003, 10:23 AM
I have coded something that will either show or delete a line depending on the date, the only problem is that if a row gets deleted during the "while" loop it will cause an error as it wasnt expecting to lose a value from the mysql_fetch_row() array.

Here is my code...


while(list($band,$country,$months,$lastdate,$support,$date) = mysql_fetch_row($result)) {
$today = time();
$d = split("-",$lastdate);
$date_seconds = mktime(0,0,0,$d[2],$d[1],$d[0]);
if ($today > $date_seconds) {
$result = mysql_query("DELETE FROM gig_listings WHERE band = '$band' AND country = '$country' LIMIT 1");
}
else {
echo "<br><a href=\"show.php?band=$band&country=$country\">$band</a> ($months)";
}
}

I get the error: Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in *path*\list.php on line 16
(line 16 is the one with the while() on it)
It works fine, just as long as there is no data to delete! Any help would be much appreciated!

Khalid Ali
11-23-2003, 11:23 AM
this typically means that there si no results in the $result object,make sure your uery does return something....

nuthead
11-23-2003, 11:43 AM
its because it gets confused with a row getting deleted, there is information to return, it wont bring up the error unless it deletes a row

nuthead
11-23-2003, 03:46 PM
its ok, ive sorted it now...