print message when result is empty

The place for general PHP questions and hints for PHP on IBM i

print message when result is empty

Postby barr5887 on Wed May 18, 2016 5:55 pm

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>


<?php


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

while(db2_fetch_row($queryexe))
{
$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("<table>");
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");
}
print("</tr>");
print("</tbody>");
print("</table>");
db2_close($conn);
?>




Thanks for any assistance,
bgg
barr5887
 
Posts: 9
Joined: Tue Sep 09, 2014 8:31 pm

Re: print message when result is empty

Postby scottgcampbell on Thu May 19, 2016 1:14 pm

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.

Scott
scottgcampbell
 
Posts: 187
Joined: Wed Apr 22, 2009 2:29 pm
Location: Edmonton, AB, Canada

Re: print message when result is empty

Postby josh2698 on Thu Dec 29, 2016 2:55 pm

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


Return to PHP Questions / Hints

Who is online

Users browsing this forum: No registered users and 1 guest