DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   PHP (http://www.daniweb.com/forums/forum17.html)
-   -   Double MySQL Query (http://www.daniweb.com/forums/thread7350.html)

Ragnarok Jun 22nd, 2004 1:53 pm
Double MySQL Query
 
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.

Killer_Typo Jun 22nd, 2004 2:12 pm
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.

Ragnarok Jun 22nd, 2004 5:10 pm
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

mugur Jul 19th, 2007 8:50 pm
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)

JeniF Aug 25th, 2007 5:38 pm
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());


All times are GMT -4. The time now is 11:05 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC