Jump to content

If, else script help


Andrew R

Recommended Posts

Hi,

I was wondering why this script (below) isn't working.  For example, when the inputs, day, aircraft, departure, arrival = Any, why does the echo, "Day, Aircraft, Departure, Arrival = Any" not display?

[code]$day=$_POST["day"];
$aircraft=$_POST["aircraft"];
$departure=$_POST["departure"];
$arrival=$_POST["arrival"];

if ($day == "Any") {
echo 'Day = Any';
}

elseif ($aircraft == "Any") {
echo 'Aircraft = Any';
}

elseif ($departure == "Any") {
echo 'Departure = Any';
}

elseif ($arrival == "Any") {
echo 'Arrival = Any';
}

elseif ($day && $aircraft && $departure && $arrival == "Any") {
echo 'Day, Aircraft, Departure, Arrival = Any';
}

[/code]

Cheers
Link to comment
Share on other sites

This should work :)
[code]<?php
$day=$_POST["day"];
$aircraft=$_POST["aircraft"];
$departure=$_POST["departure"];
$arrival=$_POST["arrival"];

if ($day == "Any") {
echo 'Day = Any';
}

elseif ($aircraft == "Any") {
echo 'Aircraft = Any';
}

elseif ($departure == "Any") {
echo 'Departure = Any';
}

elseif ($arrival == "Any") {
echo 'Arrival = Any';
}

elseif ($day == "Any" && $aircraft == "Any" && $departure == "Any" && $arrival == "Any") {
echo 'Day, Aircraft, Departure, Arrival = Any';
}
?>[/code]
Link to comment
Share on other sites

Cheers  :), although its still not working. Somehow I need a script that if Day does = Any it will not just pick the first if statement that applies to Day = Any.  I need it to search through all the statements to find the right one.  So if all the values (day, aircraft, departure, arrival) = Any it will find that if statement.

Cheers
Link to comment
Share on other sites

Try switching the if they all = any and the first expression you had. This way it checks to see if they all = any first, then if it doesn't it will run through the rest of them.

[code]<?php
$day=$_POST["day"];
$aircraft=$_POST["aircraft"];
$departure=$_POST["departure"];
$arrival=$_POST["arrival"];

if ($day == "Any" && $aircraft == "Any" && $departure == "Any" && $arrival == "Any") {
echo 'Day, Aircraft, Departure, Arrival = Any';
}

elseif ($day == "Any") {
echo 'Day = Any';
}

elseif ($aircraft == "Any") {
echo 'Aircraft = Any';
}

elseif ($departure == "Any") {
echo 'Departure = Any';
}

elseif ($arrival == "Any") {
echo 'Arrival = Any';
}
?>[/code]
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.