crmamx Posted February 16, 2011 Share Posted February 16, 2011 How do I execute display.php if condition is true? I have only included relevant code. $query = "SELECT * FROM airplanes WHERE ama='$ama'"; if (mysql_num_rows($result) == 0) { //print error message if (mysql_num_rows($result) == 1) { // execute display.php. How do I do this? I do plan on changing the 2 ifs to if/else Quote Link to comment Share on other sites More sharing options...
petroz Posted February 16, 2011 Share Posted February 16, 2011 If display.php isnt a class with methods and its just procedural... just "include" it, like so. include "display.php" Quote Link to comment Share on other sites More sharing options...
lalnfl Posted February 16, 2011 Share Posted February 16, 2011 $query = "SELECT * FROM airplanes WHERE ama='$ama'"; if (mysql_num_rows($result) == 0) { $errormsg = "error"; } else (mysql_num_rows($result) == 1) { header("Location: http://www.mywebsite.com/display.php"); exit(); } Quote Link to comment Share on other sites More sharing options...
petroz Posted February 16, 2011 Share Posted February 16, 2011 header is only going to redirect..... It would not execute display.php within his current script. Quote Link to comment Share on other sites More sharing options...
lalnfl Posted February 16, 2011 Share Posted February 16, 2011 True. Quote Link to comment Share on other sites More sharing options...
ronverdonk Posted February 16, 2011 Share Posted February 16, 2011 As petroz already said: $query = "SELECT * FROM airplanes WHERE ama='$ama'"; if (mysql_num_rows($result) == 0) { $errormsg = "error"; } elseif (mysql_num_rows($result) == 1) { include "display.php"; // from here it executes diisplay.php } Quote Link to comment Share on other sites More sharing options...
petroz Posted February 16, 2011 Share Posted February 16, 2011 Another note... Switch is an old school method for for dealing with conditions.. here is an example. $sql = "SELECT * FROM airplanes WHERE ama='$ama'"; $query = mysql_query($sql); $rows = mysql_num_rows($query); switch ($rows) { case 0: echo "Error!!!!"; break; case 1: include 'display.php'; break; default: echo "we found more than one!"; break; } Quote Link to comment Share on other sites More sharing options...
crmamx Posted February 16, 2011 Author Share Posted February 16, 2011 I used the include and works just fine. I use the include in this program to connect to the db, but I thought the include was something like a subroutine, where it goes to and executes the include and then returns to this program. One of the disadvantages of being an old school mainframe programmer. Thanks guys. Quote Link to comment 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.