At 1:23 AM -0600 2000-01-21, Matt Wagner wrote:
>Kole Dunn writes:
>> Hi,
>> My MySQL database works just great, and I do a SELECT on items based
>> on a keyword query from a web site and it returns the matches. I now
>> need to display a message "There were no matches" when nothing is
>> matched in the database. I'm using Perl/DBI, does anyone have a
>> helpful code snip I can use?
>
>my $query = $dbh->prepare(...);
>$query->execute or die "...";
>
>if ($query->rows == 0) {
> print "There were no matches.";
>}
>
>look at DBI docs.
Actually, the DBI docs say that you can't count on the rows method
being accurate for SELECT statements, and that you should count
the rows as you fetch them.
I often use logic something like this for the case in point:
prepare
execute
count = 0
while (fetch next row succeeds)
{
if count is 0 print any headers that are needed
print row
++count
}
finish
if count is 0
print that there were no rows
--
Paul DuBois, paul@stripped