mysql_affected_rows with DELETE?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

mysql_affected_rows with DELETE?

Post 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? :(
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

try

Code: Select all

$count2 = mysql_affected_rows();
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

Post 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?
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post 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
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

Post by Coco »

uh?
*drops another 50p coin in the box*
ahhh
thanks :)
Post Reply