php - Changing Multiple values in MySQL with a single Query -


i want change different column values of table in 1 query, possible?

i tried (just guess):

<?php $q="update tab set name='samit' id='1' && set name='anju' id='4'"; $run=mysql_query($q); if($run){ echo 'updated'; } else{ echo 'update failed'; } ?> 

it's not working. can using loop, loop increase operation time.

you can use join

update tab t1 join tab t2     on t1.id = 1 , t2.id = 4    set t1.name = 'samit',        t2.name = 'anju' 

here sqlfiddle demo


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -