Page 1 of 1

mysql_affected_rows with DELETE?

Posted: Thu May 29, 2003 8:16 am
by Coco
If this belongs in the php forum.... sorry twig :(

Ok, im trying to find out how many rows are deleted, but im having problems :(
Heres the code ive got now:

Code: Select all

<?php
$query3 = 'DELETE FROM bods WHERE owner = ' . $data['id'] . ' AND type = ' . 
						$HTTP_POST_VARS['bodtype'] . ' AND quality = ' . 
						$HTTP_POST_VARS['qual'] . ' AND number = ' . 
						$HTTP_POST_VARS['quant'] . ' AND part =  1 AND metal = ' . 
						$HTTP_POST_VARS['metal'] . ' LIMIT ' . $count;
$result3 = mysql_query($query3);
echo mysql_error() . $query3;
$count2 = mysql_affected_rows($result3);

?>
I also tried mysql_num_rows. Now as far as i can tell from the mysql manual, even if there are no valid rows from the WHERE then it will return a number. Everything i try gives invalid result resource errors... Now i know i can suppress these errors with an @, but i need those numbers for the script :( I know that the query's themselves work, because the rows that should be deleted are being deleted. Any ideas what is wrong? :(

Posted: Thu May 29, 2003 8:27 am
by Wayne
try

Code: Select all

$count2 = mysql_affected_rows();

Posted: Thu May 29, 2003 10:33 am
by Coco
Ok that worked... but whats the point in the php manual stating that mysql_affected_rows takes a 'resource link_identifier' if it doesnt work when you put one?

Posted: Thu May 29, 2003 10:39 am
by Wayne
$result3 wouldnt be the link identifier, the link identifier would be what you assigned the mysql_connect() to.

like
$link = mysql_connect(xxx);
$link would be the link identifier

Posted: Thu May 29, 2003 2:12 pm
by Coco
uh?
*drops another 50p coin in the box*
ahhh
thanks :)