Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Beginer, sql display message if no value

Status
Not open for further replies.

jpillonel

Programmer
Dec 17, 2003
61
CH
Hello,
I have a perl script that connect to a mysql database.

Sometimes a query does not return any row. In the case if there is no rows, how can I print a message like "no row prensent" ?

(how can I insert a if condition that check the rows returned in the while loop ?)

Thanks

Code:
$retocaisse_sql = $dbh->prepare("select DATE_FORMAT(eventtimestamp, '%d%m%y'), count(*)
                                        from msc
                                        where receiverid=$idcaisse
                                                and statustypid=200
                                                and DATE_FORMAT(eventtimestamp, '%d%m%y') BETWEEN @datelistingV2 and $datejourbrut
                                                group by DATE_FORMAT(eventtimestamp, '%d%m%y') ");
                        $retocaisse_sql->execute;
                        print "\nRetours reçus";

while( ($date_retour, $retocaisse) =$retocaisse_sql->fetchrow() ) {
                        print "Date: $date_retour Retours reçus: $retocaisse \n";
 
Hi

Code:
$retocaisse_sql->execute;
print "\nRetours reçus";

[red]$nr=0;[/red]

while( ($date_retour, $retocaisse) =$retocaisse_sql->fetchrow() ) {
  print "Date: $date_retour Retours reçus: $retocaisse \n";
  [red]$nr++;[/red]
}

[red]unless ($nr) print "no matching data found\n";[/red]

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top