You are here: Re: select on updated value during the fetch « PHP Programming Language « IT news, forums, messages
Re: select on updated value during the fetch

Posted by Kimmo Laine on 11/23/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)

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация