| 
	
 | 
 Posted by cdtsly on 06/14/23 11:50 
in fact, i need this order because i am rebuilding a table and i need 
to do this way 
 
i have a workaround with generating no fetch of all the table, but to 
select the rows one by one 
which give a stupid number of query( 200 000 rows=>200 000 query) and 
it take a lot of time naturally :-) 
 
i made this example to show my problem 
 
is not there a possibility to fetch a special way which can take in 
consideration freshness? 
 
 
Kimmo Laine a écrit : 
 
> <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] 
 |