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

Link to comment
Share on other sites

$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
Share on other sites

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
Share on other sites

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