|
Posted by Kimmo Laine on 12/18/41 11:50
<cdtsly@relayeur.com> wrote in message
news:1150450217.111881.169080@c74g2000cwc.googlegroups.com...
> the update works for the updated column
> but as you say the prefetch row are already there
> so the mysql_fetch_array command will take a line where there is not
> anymore the str=4 value
>
> i know why i have this problem and i like to know how not have it
> :-)
Run the queries in different order. First update, then select.
like this:
$query7="UPDATE val SET str='7',updated='1' WHERE val='2'";
$result7=mysql_db_query($datamysql,$query7);
$query="SELECT * FROM val WHERE str='4'";
$result=mysql_db_query($datamysql,$query);
while ($row=mysql_fetch_array($result))
{
$str=$row["str"];
$val=$row["val"];
$query2="UPDATE val SET str='5' WHERE val='$val'";
$result2=mysql_db_query($datamysql,$query2);
}
Well actually, to keep it very very very simple, you could just do this:
$query7="UPDATE val SET str='7',updated='1' WHERE val='2'";
$result7=mysql_db_query($datamysql,$query7);
$query2="UPDATE val SET str='5' WHERE str='4'";
$result2=mysql_db_query($datamysql,$query2);
And nothing else. If you want to update all rows where str='4', then use
that as the condition, you don't need to first select something with one
condition, and then one by one row update all the rows. You can do it all in
one update query.
--
"ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk
spam@outolempi.net | Gedoon-S @ IRCnet | rot13(xvzzb@bhgbyrzcv.arg)
[Back to original message]
|