The Do...While Diddy or How to exit a routine...

From: Date: Sat, 01 Jul 2000 23:15:58 +0000
Subject: The Do...While Diddy or How to exit a routine...
Groups: php.general 
Request: Send a blank email to php-general+get-4319@lists.php.net to get a copy of this message
Well, I was proud of myself that I was able to code a news page with next/prev buttons with odbc. I wanted to put a list of the five most recent headlines on the page. The query worked fine. However, that excitement was tempered by the fact that I can't seem to code a statement that will fetch results of a query until either they end or reach 5 lines, whichever comes first. Right now my code is this: <? $topnews=1; $connect = odbc_connect("blah", "blah", "blah"); $query = "SELECT headline, date FROM news ORDER BY date DESC"; $result = odbc_do($connect, $query); while (odbc_fetch_row($result)) { $headline = odbc_result($result, headline); echo ("$headline<br /><br />\n"); $topnews++; if ($topnews = 5) { odbc_close($connect); exit; } } odbc_close($connect); ?> Right now the code displays the headline but doesn't display the rest of the page that comes after the ?>. From scouring the manual I see that exit may be my culprit. What else would work and is there a way to make the code a little more compact. Having fun coding parts of the site with PHP and love the advice I've been reading here. Thanks in advance. -- Ian Evans

« previous php.general (#4319) next »