note 32357 added to function.mysql-query
| From: | gwaddell at gwaddell dot com | Date: | Sun, 25 May 2003 05:25:39 +0000 |
| Subject: | note 32357 added to function.mysql-query | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-48975@lists.php.net to get a copy of this message | ||
Pete Kelly, there is a reason the second example for UPDATE is slower from your code. It is working
across all rows to perform the UPDATE. Your Example 1 only changes 1 row.
if($row = mysql_fetch_array($rs))
{
mysql_query("UPDATE users SET visits=visits+1 WHERE id =
'".$row["id"]."'");
}
would have to change to a while loop to be an equal test:
while( $row = mysql_fetch_array( $rs ) )
{
mysql_query( "UPDATE users SET visits=visits+1 WHERE id =
'".$row["id"]."'" );
}
(test for no rows returned .: do an INSERT, is not shown)
Graham Waddell
----
Manual Page -- http://www.php.net/manual/en/function.mysql-query.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32357
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32357&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32357&report=yes