Code Comments
Programming Forum and web based access to our favorite programming groups.I'm flummoxed. How do I get mySQL to run a synchronous series of queries, waiting for each query to execute fully before sending the next? Thanks for any help :) ---------------------------------------- The post originated from PHP Freaks: ---------------------------------------- http://www.phpfreaks.com http://www.phpfreaks.com/forums
Post Follow-up to this messageHave you found a way of doing it otherwise from the same script? Barand http://members.aol.com/barryaandrew...agridguide.html easy data tables - and more ---------------------------------------- The post originated from PHP Freaks: ---------------------------------------- http://www.phpfreaks.com http://www.phpfreaks.com/forums
Post Follow-up to this messageUmm... I'm just assuming that the problem with my script is that it's asynchronous. I have it executing a loop, each time it goes through it sends a couple of queries... but it only works with a certain number of times looping, then it just stops and sends me errors. If I make it echo a few characters each time it loops, though, it seems to slow it down enough so that it will work. Is there some other reason as to why it wouldn't be able to handle a large number of queries without the echo? ---------------------------------------- The post originated from PHP Freaks: ---------------------------------------- http://www.phpfreaks.com http://www.phpfreaks.com/forums
Post Follow-up to this messageHere's the script...
--------
getshows = mysql_query("SELECT * FROM shows WHERE run =
'no' AND showType LIKE '%cats%' AND runDate <=
'today'",connect);
while (sh = mysql_fetch_object(getshows))
{
getclass = mysql_query("SELECT classID, fee FROM
classes WHERE showID = sh->showID",connect);
while (cl =
mysql_fetch_object(getclass)) {
fee = cl->fee;
prize1 = (5 * fee);
prize2 = (3 * fee);
prize3 = (2 * fee);
i = 1;
orderscore = mysql_query("SELECT * FROM entries
WHERE classID = cl->classID ORDER BY score
DESC",connect);
while (order =
mysql_fetch_object(orderscore)) {
place = i++;
mysql_query("UPDATE entries SET place =
place WHERE classID = cl->classID AND catID =
order->catID",connect);
echo "12345.";
if (place < 7) {
add = 11 - place;
if (place == 1) {
mysql_query("UPDATE cats SET firsts =
firsts + 1, winnings = winnings + prize1 WHERE catID =
order->catID");
owner = mysql_query("SELECT ownerID
FROM cats WHERE catID =
order->catID",connect);
o =
mysql_fetch_object(owner);
mysql_query("UPDATE members SET bankMoney
= bankMoney + prize1 WHERE memberID =
o->ownerID",connect);
}
elseif (place == 2) {
mysql_query("UPDATE cats SET places =
places + 1, winnings = winnings + prize2 WHERE catID =
order->catID",connect);
owner = mysql_query("SELECT ownerID
FROM cats WHERE catID =
order->catID",connect);
o =
mysql_fetch_object(owner);
mysql_query("UPDATE members SET bankMoney
= bankMoney + prize2 WHERE memberID =
o->ownerID",connect);
}
elseif (place == 3) {
mysql_query("UPDATE cats SET places =
places + 1, winnings = winnings + prize3 WHERE catID =
order->catID",connect);
owner = mysql_query("SELECT ownerID
FROM cats WHERE catID =
order->catID",connect);
o =
mysql_fetch_object(owner);
mysql_query("UPDATE members SET bankMoney
= bankMoney + prize3 WHERE memberID =
o->ownerID",connect);
}
else {
mysql_query("UPDATE cats SET places =
places + 1 WHERE catID =
order->catID",connect);
}
}
else {
add = 1;
}
mysql_query("UPDATE cats SET points = points +
add WHERE catID =
order->catID",connect);
}
}
mysql_query("UPDATE shows SET run = 'yes' WHERE
showID = sh->showID",connect);
}
--------
----------------------------------------
The post originated from PHP Freaks:
----------------------------------------
http://www.phpfreaks.com
http://www.phpfreaks.com/forums
Post Follow-up to this messageI usually find that where someone is executing a query then looping through it and executing another query in each loop, then the whole thing could be accomplished by a single joined query. Do you want to post the queries? Barand http://members.aol.com/barryaandrew...agridguide.html easy data tables - and more ---------------------------------------- The post originated from PHP Freaks: ---------------------------------------- http://www.phpfreaks.com http://www.phpfreaks.com/forums
Post Follow-up to this messageMuch obliged :) ---------------------------------------- The post originated from PHP Freaks: ---------------------------------------- http://www.phpfreaks.com http://www.phpfreaks.com/forums
Post Follow-up to this messageA single joined query would save those 2 outer loops. Check for change of showID as you loop thru and update each as being run. -------- SELECT shows.* , classes.fee, entries.* FROM (shows INNER JOIN classes ON shows.showID = classes.showID) INNER JOIN entries ON classes.classID = entries.classID WHERE shows.run = 'no' AND show.showType LIKE '%cats%' AND shows.runDate <= 'today'" ORDER BY chows.showID, classes.classID,entries.score DESC -------- hth Barand http://members.aol.com/barryaandrew...agridguide.html easy data tables - and more ---------------------------------------- The post originated from PHP Freaks: ---------------------------------------- http://www.phpfreaks.com http://www.phpfreaks.com/forums
Post Follow-up to this message"sapphyre" wrote: > I’m flummoxed. > > How do I get mySQL to run a synchronous series of queries, waiting for > each query to execute fully before sending the next? > > Thanks for any help > > > > ---------------------------------------- > The post originated from PHP Freaks: > ---------------------------------------- > http://www.phpfreaks.com > http://www.phpfreaks.com/forums As this a php related group, I presume the queries are sent via php to mysql. If one script is sending the sql’s, then they are actually executing in order as you described. The exception would be if you do "delay insert". -- http://www.dbForumz.com/ This article was posted by author's request Articles individually checked for conformance to usenet standards Topic URL: http://www.dbForumz.com/PHP-SQL-Syn...pict140909.html Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz .com/eform.php?p=471761
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.