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 Link to comment https://forums.phpfreaks.com/topic/227923-how-to-jump-to-program-if-condition-is-true/ 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" Link to comment https://forums.phpfreaks.com/topic/227923-how-to-jump-to-program-if-condition-is-true/#findComment-1175302 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(); } Link to comment https://forums.phpfreaks.com/topic/227923-how-to-jump-to-program-if-condition-is-true/#findComment-1175304 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. Link to comment https://forums.phpfreaks.com/topic/227923-how-to-jump-to-program-if-condition-is-true/#findComment-1175306 Share on other sites More sharing options...
lalnfl Posted February 16, 2011 Share Posted February 16, 2011 True. Link to comment https://forums.phpfreaks.com/topic/227923-how-to-jump-to-program-if-condition-is-true/#findComment-1175307 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 } Link to comment https://forums.phpfreaks.com/topic/227923-how-to-jump-to-program-if-condition-is-true/#findComment-1175311 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; } Link to comment https://forums.phpfreaks.com/topic/227923-how-to-jump-to-program-if-condition-is-true/#findComment-1175316 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. Link to comment https://forums.phpfreaks.com/topic/227923-how-to-jump-to-program-if-condition-is-true/#findComment-1175319 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.