Re: Where to handle no results
| From: | Comron E Sattari | Date: | Mon, 03 Jul 2000 20:36:07 +0000 |
| Subject: | Re: Where to handle no results | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-4573@lists.php.net to get a copy of this message | ||
after the $result = line try:
if(odbc_num_rows($result) == 0) die;
although for some reason my odbc driver always gives me -1 rows in a result,
no matter what. So this may not work. Otherwise, maybe someone else much
wiser than I can help you out.
Comron
----- Original Message -----
From: "Digital Hit Entertainment" <ianevans@friedspamdigitalhit.com>
To: <php-general@lists.php.net>
Sent: Monday, July 03, 2000 9:34 AM
Subject: [PHP] Where to handle no results
> 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
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>