Jump to content


Photo

php query help


  • Please log in to reply
2 replies to this topic

#1 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 06 April 2006 - 12:52 AM

lol back again needed a lil help
okay i succefully got the data from the multiple select option form to insert but not i need to know how to updat two or more rows at the same time for example

Username ID status
___________________________
saad 1 admin
alex 2 n00b
KB 3 n00b
darkness 4 member


and i want to update the 'id' colum for user both saad and darkness

<?php
$result = mysql_query("UPDATE status SET id= id + 1 WHERE username='saad'")
or die(mysql_error());
?>

but this would only update for 1 user
ive tried " AND 'darkness"
" , 'darkness"
" AND username = 'darkness' etcc..
and lots of other stuff can som1 help me with this if its possiable

and i need it so it can update unlimited amount of rows

#2 Javizy

Javizy
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 06 April 2006 - 03:05 AM

[!--quoteo(post=362093:date=Apr 6 2006, 01:52 AM:name=desithugg)--][div class=\'quotetop\']QUOTE(desithugg @ Apr 6 2006, 01:52 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
lol back again needed a lil help
okay i succefully got the data from the multiple select option form to insert but not i need to know how to updat two or more rows at the same time for example

Username ID status
___________________________
saad 1 admin
alex 2 n00b
KB 3 n00b
darkness 4 member
and i want to update the 'id' colum for user both saad and darkness

<?php
$result = mysql_query("UPDATE status SET id= id + 1 WHERE username='saad'")
or die(mysql_error());
?>

but this would only update for 1 user
ive tried " AND 'darkness"
" , 'darkness"
" AND username = 'darkness' etcc..
and lots of other stuff can som1 help me with this if its possiable

and i need it so it can update unlimited amount of rows
[/quote]

You would use OR instead of AND, or a shortened version IN (as I was told earlier).

UPDATE status
SET id = id + 1
WHERE username IN ('saad', 'alex', 'KB' );


#3 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 06 April 2006 - 11:58 AM

[!--quoteo(post=362124:date=Apr 5 2006, 11:05 PM:name=Javizy)--][div class=\'quotetop\']QUOTE(Javizy @ Apr 5 2006, 11:05 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
You would use OR instead of AND, or a shortened version IN (as I was told earlier).

UPDATE status
SET id = id + 1
WHERE username IN ('saad', 'alex', 'KB' );
[/quote]


umm lol looks like will work lol il try t later g2g to school thnx





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users