RE: [PHP] while loop

From: Date: Wed, 08 Nov 2000 15:35:42 +0000
Subject: RE: [PHP] while loop
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-24329@lists.php.net to get a copy of this message
> -----Original Message----- > From: Ali [mailto:arsajedi@bupnet.de] > Sent: Wednesday, November 08, 2000 9:14 AM > To: php-general@lists.php.net > Subject: [PHP] while loop > > > I have got a while loop which retrieve data from a DB. Within this while > loop I have got another while loop which retrieve its data from > the same DB if the if statement is fulfilled. My piece of code looks: > > <? > if ($action == "alle") { > $sql = "SELECT * FROM Rubriken ORDER BY rub_id"; > $q -> query ($DB, $sql); > while ($row = $q ->getrow()) { > echo $row['rubrik']; > if ($rubrik == $row['run_name']) { > $sql = "SELECT * FROM $rubrik ORDER BY id"; > $q -> query ($DB, $sql); > $num = $q -> numrows(); > if ($num > 0) { > while ($row = $q ->getrow()) { > echo $row['unterrubrik']; > } > } > } > } > } > ?> > > Now my problem is that when $rubrik does not exists the first while loop > works fine. But when $rubrik exists the first while loop stops after doing > the second loop for the first time. Does anyone know why the first loop > behaves like this and not going through. I appreciate any help. Thank you. You're using the same variables for the results of both queries, which means that the query performed in your inner loop overwrites the outer one. Try replacing $q with $q1 and $q1 and $row with $row1 and $row2 as appropriate and see whether you don't get something more like what you expected. --- Mark Roedel | "Blessed is he who has learned to laugh Systems Programmer | at himself, for he shall never cease LeTourneau University | to be entertained." Longview, Texas, USA | -- John Powell

« previous php.general (#24329) next »