Where to handle no results

From: Date: Mon, 03 Jul 2000 16:34:16 +0000
Subject: Where to handle no results
Groups: php.general 
Request: Send a blank email to php-general+get-4525@lists.php.net to get a copy of this message
I know I saw a snippet on how to handle this somewhere. Surfed all the PHP sites I've been visiting in this last week, but haven't been able to re-stumble across the info again. In the code below I'm trying to have the snippet stop executing if it doesn't find any results in the database. I looked in the docs and thought placing an "or break;" after the $result line would work but no. Thanks in advance. <? // Top 5 News start $topnews=0; $connect = odbc_connect("bla", "bla", "bla"); $query = "SELECT article_id, headline, date, celebs FROM news WHERE celebs LIKE '%$celebname%' ORDER BY date DESC"; $result = odbc_exec($connect, $query); echo "<div align=\"right\"><table align=\"right\" width=\"150\" bgcolor="\#010184\" border=\"0\" cellspacing=\"1\" cellpadding=\"2\">\n"; echo "<tr><td bgcolor=\"white\" class=\"ln\" valign=\"top\" align=\"left\"><b>Recent Headlines</b><br />"; while (odbc_fetch_row($result)) { $topheadline = odbc_result($result, headline); $id = odbc_result($result, article_id); echo ("<a href=\"/news/story.shtml/$id\">$topheadline</a><br />\n"); $topnews++; if ($topnews > 5) { odbc_close($connect); break; } } echo "</td></tr></table></div>"; odbc_close($connect); // Top 5 News end ?> -- Ian Evans

« previous php.general (#4525) next »