cancel
Showing results for 
Search instead for 
Did you mean: 

PHP - Chained queries nested in "while" loops

Former Member
0 Kudos

Hello,

would like to know if someone already saw the issue i'm facing and how to avoid it.

I have some code parts looking like :

$query="SELECT id FROM ... WHERE ...";
$result=maxdb_query($link, $query);
while($object=maxdb_fetch_object($result)) {
    $query2="SELECT id FROM ... WHERE id='".$object->ID."' ...";
    $result2=maxdb_query($link, $query2);
    while($object2=maxdb_fetch_object($result2)) {
       echo $object2->ID;
       ...
    }
    maxdb_free_result($result2);
}
maxdb_free_result($result);

But it seems it doesn't like it, indeed, when such a part of the program is reached, Apache is firing a download emptied PHP webpage.

Any help appreciated.

Accepted Solutions (1)

Accepted Solutions (1)

Nigel_James
Active Contributor
0 Kudos

Some thoughts...

Does it still happen if you take the internal query out?

Is there a way you can avoid the chained query?

Either in a join or by writing a stored proc in maxdb?

Cheers,

Nigel

Former Member
0 Kudos

Hi Nigel,

Thank you for your answer

I don't think i could use stored proc because of one particular case, so it is very annoying...

Does something could explain the problem ?

Thank again

Nigel_James
Active Contributor
0 Kudos

Yes is it wierd but I still maintain that you could write this as a join.

Have you tried commenting the inner loop? Does it still dump?

Nigel

Answers (1)

Answers (1)

Former Member
0 Kudos

Hello dinard,

Can you specify why exactly do you want to use nested "while" loops?

I would use any kind of outer join on the query, in order to avoid your situation.