From: Michael Dykman Date: January 20 2011 5:45am Subject: Re: running a mysql query inside a loop of another without a sync error List-Archive: http://lists.mysql.com/mysql/224123 Message-Id: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable From 10000 feet, what you are attempting to do looks like it would be very easily accomplished with a join, leaving you with 1 result set to process. I realize that isn't the question, but it might be a solution. - michael dykman On Wed, Jan 19, 2011 at 9:54 PM, Delan Azabani wrote: > 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 =3D mysql_use_result(mysql); > while (row =3D mysql_fetch_row(res)) { > =A0 =A0MYSQL_RES *res2; > =A0 =A0MYSQL_ROW row2; > =A0 =A0mysql_query(mysql, "some other select query using an id from the > first"); > =A0 =A0res2 =3D mysql_use_result(mysql); > =A0 =A0/* ... */ > =A0 =A0mysql_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 appreciat= ed. > > -- > Thanks and best regards, > Delan Azabani > http://azabani.com/ > > -- > MySQL General Mailing List > For list archives: http://lists.mysql.com/mysql > To unsubscribe: =A0 =A0http://lists.mysql.com/mysql?unsub=3Dmdykman@gmail= .com > > --=20 =A0- michael dykman =A0- mdykman@stripped =A0May the Source be with you.