Reputation: 7
I need to open a query inside a while loop on another query, so that it's driven by the results of the second query.
$r=new COM("ADODB.Recordset");
$g=new COM("ADODB.Recordset");
$g->Open("SELECT * FROM question ORDER BY ID;",$db);
while ($g->EOF == FALSE){
$ID=$g->Fields["ID"]->value;
$r->Open("SELECT * FROM Answers WHERE Username='".$_GET["Username"]."' AND questionID=".$ID.";",$db);
$g->MoveNext();
}
and It doesn't work.. it's ok when i put $r->open(...)
outside... but I need to use the result of the first query in it..
Upvotes: 0
Views: 208
Reputation: 841
Why don't you combine the two queries into one by using a join?
"select Answers.ID, Question.ID from Answers inner join Questions where Questions.ID=Answers.QuestionID and Answers.Username=" . $_GET["Username"]
Combine the two tables by joining the answers and questions that are related to each other.
Upvotes: 1