On Thu, 28 Aug 2003 08:54:54 -0400
"Mark Richards" <[EMAIL PROTECTED]> wrote:
> I am still quite new to MySQL and have a basic question. I am using PHP, so
> forgive me if this is more a PHP issue.
>
> I want to perform an update to a specific record based on a condition. In
> the outer loop, I have Query1, which returns set Result1. Inside this loop,
> I run an UPDATE query which returns Result2.
>
> // executed first query...
> while ($row = mysql_fetch_assoc($result1))
> {
> // get the record ID for the row we are on.
> $recid = $row["id"];
> // construct a new query
> $q2 ="UPDATE `table` SET `review` = 1 where id =
> '".$recid."';";
> $result2 = mysql_query($q2)
> }
You don't need execute UPDATE's in the loop in this case.
Try smthing like that:
<?
.....
$ids = Array();
while ($row = mysql_fetch_assoc($result1))
{
$ids[] = $row["id"];
}
$ids_string = implode(',',$ids);
//of course, we need to check if $id_string is not empty
$q2 ="UPDATE table SET review = 1 WHERE id IN (".$ids_string.")";
.....
?>
--
WBR,
Antony Dovgal aka tony2001
[EMAIL PROTECTED]
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]