Page 1 of 1

print message when result is empty

Posted: Wed May 18, 2016 5:55 pm
by barr5887
Hi all,

Pretty new to PHP.
I have this piece of code which I've inherited.
How can I modify it to where, if the Select statement doesn't return any data, that I can print a message stating that ' No transfers have run recently'
I was thinking of some sort of $result variable but not getting anywhere.

Code: Select all

if($fdsort <> "TODAY"){
   $query = "Select * from ALLFTM100.ANHISTL2 where HSSESN = '$fdsort' order by HSDATE desc, HSTIME desc";

print("<h4>Townsend transfers for $fdsort on $system starting from $slcdate in descending order by date/time.  </h4>");


<h3> <a href="javascript:history.go(-1)"style="color:blue;">Back to previous page</a></h3>
<br > </br>


//Execute query
$queryexe = db2_exec($conn, $query) ;

$HSSESN = db2_result($queryexe, 'HSSESN'); // System Name
$HSLOGI = db2_result($queryexe, 'HSLOGI'); // System Roll
$HSRETN = db2_result($queryexe, 'HSRETN'); // System Ping
$HSDATE = db2_result($queryexe, 'HSDATE'); // System Maintenance
$HSTIME  = db2_result($queryexe, 'HSTIME'); // System Telnet Status
$HSTEXT = db2_result($queryexe, 'HSTEXT'); // System FTP Status

print("<td WIDTH=100>");
print("$HSSESN</td><td width=10> <a href=http://orion/iTownsendTranslog.php?system=$system&HSLOGI=$HSLOGI&HSSESN=$HSSESN >$HSLOGI</td> <td width=10> $HSRETN</td> <td width=10> $HSDATE</td> <td width=10> $HSTIME</td> <td width=100> $HSTEXT \n");
print("</td> \n");

Thanks for any assistance,

Re: print message when result is empty

Posted: Thu May 19, 2016 1:14 pm
by scottgcampbell
Without refactoring the code it would probably be easiest to add a $count variable initialized to 0 before the while loop, then increment it in the while loop and check it after the while loop to determine if you want to print the message.


Re: print message when result is empty

Posted: Thu Dec 29, 2016 2:55 pm
by josh2698
I think by adding a $count variable initialized to 0 before while loop will work.