Re: [PHP4BETA] multiple queries

From: Date: Fri, 11 Feb 2000 05:30:19 +0000
Subject: Re: [PHP4BETA] multiple queries
References: 1  Groups: php.version4 
Request: Send a blank email to php-version4+get-10086@lists.php.net to get a copy of this message
On 10 Feb, Mike Teigen wrote: > I am trying to query three different table of the same databsae, each > output of the query is in an if statement, now each statement works > seperately but when i place all three in a row as shown only the first > one gets executed..please help!!!!! (im a newbie too! :o) > > <? > $specialQuery = "SELECT * > FROM specialReport > where showw = '1' > order by reportDate desc" > ; > $specialResult = MYSQL_QUERY($specialQuery); > $specialNumber = MYSQL_NUMROWS($specialResult);?> > <? > IF ($specialNumber > 0) : > WHILE ($i < 1): > $title = mysql_result($specialResult,$i,"title"); > $entryID = mysql_result($specialResult,$i,"entryID");?> > > <li><strong>FREE...</strong>Scott Fraser's latest Special Reports and > News Releases - view the most recent posting:<? echo "<a > > href=\"specialReportOutput.cfm?entryID=$entryID\">$title";?></a>.</font><br></li><br> > <?$i++; > ENDWHILE; > ENDIF;?> > <SNIP> several similar queries. First, can you please tell Outhouse Express to turn HTML off and to wrap lines at around 72 characters? To your problem: it looks as though you would probably only get one record displayed from the above code? Your loop WHILE ($i < 1): do stuff; $i++; would iterate once only; at the end of the first iteration $i would be incremented by one; (it appears you haven't initialised $i so it would start as 0) and it's value would be one. OK, so $i is not < 1 and the loop is finished. Now we move on to the next loop; remember that in the meantime you _haven't_ changed the value of $i and it is still one. The loop test is again $i < 1 but $i actually has a value of one so of course the loop doesn't even start. Ditto for loop three. Try coding something along these lines: <?php IF ($specialNumber > 0) : $i = 0; WHILE ($i < $specialnumber): $title = mysql_result($specialResult,$i,"title"); $entryID = mysql_result($specialResult,$i,"entryID");?> <more stuff> $i++; ENDWHILE; ENDIF; $i =0; ?> Also, have a look at the mysql_fetch_array function and the related example for another way of cycling through a mysql result set. Cheers -- David Robley | WEBMASTER & Mail List Admin RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ AusEinet | http://auseinet.flinders.edu.au/ Flinders University, ADELAIDE, SOUTH AUSTRALIA

« previous php.version4 (#10086) next »