Jump to content

How to jump to program if condition is true?


crmamx

Recommended Posts

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

$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();
          }

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
}

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;
}

 

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.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.