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
https://forums.phpfreaks.com/topic/28467-if-else-script-help/
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
https://forums.phpfreaks.com/topic/28467-if-else-script-help/#findComment-130259
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
https://forums.phpfreaks.com/topic/28467-if-else-script-help/#findComment-130268
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
https://forums.phpfreaks.com/topic/28467-if-else-script-help/#findComment-130270
Share on other sites

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.