943,688 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 11865
  • PHP RSS
Jun 22nd, 2004
0

Double MySQL Query

Expand Post »
I have been looking into ways I to cut down on MySQL Querys in a page and I was wandering if you could up to update querys into one mysql_query function like this:

[php]mysql_query("UPDATE table SET val1=val1+1, val2=val2+1 WHERE id = (int); UPDATE table SET val3=val3+1, val4=val4+1 WHERE id = (int)") or die(mysql_query());[/php]

*Note: both the (int) values are different.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Ragnarok is offline Offline
94 posts
since Mar 2004
Jun 22nd, 2004
0

Re: Double MySQL Query

not sure about the update thing, but in your or die statment you should change it to

[php]or die(mysql_error());[/php]

that way you can tell what the error might be that your recieving.

also i dont see a problem with sending various mysql query's its a good way to keep things from getting messy on a single line.
Reputation Points: 152
Solved Threads: 39
Master Poster
Killer_Typo is offline Offline
778 posts
since Apr 2004
Jun 22nd, 2004
0

Re: Double MySQL Query

it does become a problem when you have to update 5 or 6 different fields on 5 or 6 different rows when you also have a few selects and an inset into as well
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Ragnarok is offline Offline
94 posts
since Mar 2004
Jul 19th, 2007
1

Re: Double MySQL Query

mysql_query() sends an unique query (multiple queries are not supported) to the currently active database on the server (see http://www.php.net/mysql_query for more info)
Reputation Points: 16
Solved Threads: 0
Newbie Poster
mugur is offline Offline
1 posts
since Jul 2007
Aug 25th, 2007
0

Re: Double MySQL Query

try something like this:

mysql_query("UPDATE table1,table2 SET table1.val1=val1+1, table1.val2=val2+1 , table2.val3=val3+1, table2.val4=val4+1 WHERE id = (int)") or die(mysql_error());
Reputation Points: 10
Solved Threads: 5
Junior Poster in Training
JeniF is offline Offline
52 posts
since Aug 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Teaching yourself PHP for idiots
Next Thread in PHP Forum Timeline: Passing Variables





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC