Jump to content

print message when Query result is empty


bggas400

Recommended Posts

if ($fdsort == "TODAY"){
$query = "Select * from ALLFTM100.ANHISTL2 where HSDATE >= '$slcdates' ";
print("<h4>Townsend transfers on $system for $slcdate only. </h4>");
}

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 listed in descending order by date/time starting from $slcdate.  </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);
?>

Hi,

 

 

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 or echo a message stating that...  "No transfers have run recently"?

I was thinking of some sort of $result variable but I'm not getting anywhere.

 

This is running on the IBM i - iSeries.

 

Thanks for any assistance,

bgg

Edited by bggas400
Link to comment
Share on other sites

I am unfamiliar with your choice of database interface. Check your manual to see what functions are available to test the results of your query (which you fail to do) and to find out how many rows were returned, which is usually available.

Link to comment
Share on other sites

Store the result of your query into an array rather than printing it immediately. Then you can check if the array length is 0 or not before displaying the results.

$data = [];
while(db2_fetch_row($queryexe))
{
    $data[] = [
      '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
    ];
}

if (count($data) == 0){
   echo "No results";
}
else {
   //Show results
}
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.