bggas400 Posted May 18, 2016 Share Posted May 18, 2016 (edited) 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 May 18, 2016 by bggas400 Quote Link to comment https://forums.phpfreaks.com/topic/301208-print-message-when-query-result-is-empty/ Share on other sites More sharing options...
ginerjm Posted May 18, 2016 Share Posted May 18, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/301208-print-message-when-query-result-is-empty/#findComment-1533070 Share on other sites More sharing options...
kicken Posted May 20, 2016 Share Posted May 20, 2016 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 } Quote Link to comment https://forums.phpfreaks.com/topic/301208-print-message-when-query-result-is-empty/#findComment-1533108 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.