List:General Discussion« Previous MessageNext Message »
From:Delan Azabani Date:January 20 2011 2:54am
Subject:running a mysql query inside a loop of another without a sync error
View as plain text  
Hi all,

I'm using MySQL with C in a CGI application. I hope this is the right
list to ask for help.

If I have this simplified code:

MYSQL_RES *res;
MYSQL_ROW row;
mysql_query(mysql, "some select query");
res = mysql_use_result(mysql);
while (row = mysql_fetch_row(res)) {
    MYSQL_RES *res2;
    MYSQL_ROW row2;
    mysql_query(mysql, "some other select query using an id from the
first");
    res2 = mysql_use_result(mysql);
    /* ... */
    mysql_free_result(res2);
}
mysql_free_result(res);

Whenever I run the second query, inside the loop, I get the nasty
'commands out of sync' error. How can I run a select query while in a
loop fetching rows from another select query? Or, do I have to fetch all
the rows completely first and store them in memory (which wouldn't be
very 'nice' to do)?

If someone could help me with this problem, it would be greatly appreciated.

-- 
Thanks and best regards,
Delan Azabani
http://azabani.com/
Thread
running a mysql query inside a loop of another without a sync errorDelan Azabani20 Jan
  • Re: running a mysql query inside a loop of another without a syncerrorMySQL)20 Jan
  • Re: running a mysql query inside a loop of another without a sync errorMichael Dykman20 Jan