[thelist] mysql_affected_rows();
Dunstan Orchard
dunstan at 1976design.com
Fri Sep 27 14:43:12 CDT 2002
Hey chris,
// images query
$sql = ("UPDATE images SET title = '$title', date_shot = '$date_shot' WHERE
imageid = '$imageid'");
// run query
mysql_query($sql);
// count rows affected
$noar = mysql_affected_rows();
// do errors
if ($noar == 0)
{
$edit_images_update_error = "1";
}
else
{
$edit_images_update_error = "0";
}
> Actually it seems to be working correctly, except that you have your
> comparison value enclosed in single quotes. Change this:
>
> if ($noar == '0')
>
> to this:
>
> if ($noar == 0)
hmm, that hasn't worked either - it's still the same wrong-way-round result.
> mysql_affected_rows() returns an integer result, and if you compare it
> to a string PHP will implicitly convert the integer result to a string
> (IIRC) which is NOT the same as comparing integers to integers. At
> that point you're comparing character values.
oh.
it works fine for all my other queries... must have been lucky...
Ah, just found this:
"...it appears that the number of affected rows returned per above in an
update query will be the number whose values were actually changed. So
updating a unique record whose value is "somevalue1" to "somevalue1" will
return zero rows affected. Whereas updating a unique record of "somevalue1"
to "somevalue2" will return '1'."
So it _is_ deciding that as my record hasn't changed, it doesn't count
as 'updated'?
Also, this is in the php manual, does it mean that I should change my code to
this 'mysql_connect' thing?:
"[Editor's Note: Review the above documentation carefully! mysql_affected_rows
() works with connection handles returned by mysql_connect() or mysql_pconnect
(), not with result handles returned by mysql_query() or mysql_db_query()"
Thanks!
- dunstan :op
p.s. re. putting brackets around my query - I just prefer it that way for some
reason, but thankyou :o)
---------------------------
Dorset, England
http://www.1976design.com/
http://www.orchard.it/
http://www.maccaws.org/
More information about the thelist
mailing list