Re: Where to handle no results

From: Date: Tue, 04 Jul 2000 01:33:50 +0000
Subject: Re: Where to handle no results
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-4630@lists.php.net to get a copy of this message
On 3 Jul, Digital Hit Entertainment wrote: > 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); <SNIP rest of code> If you were using other than ODBC, the solution would be t o do a rowcount on $result, and proceed accordingly. My alternative sugestion would be ot let the DB count the rows for you, then check that result before submitting the 'actual' query. Something like: $countquery = "SELECT count(*) as numrows FROM ews WHERE celebs LIKE '%celebname%'"; (get result however) if ($numrows == 0): break; else: do wonderful things endif; 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.general (#4630) next »