Page 1 of 1

Adding more options to an If Statement

Posted: Thu Dec 04, 2003 12:16 am
by Kailea
I'm rather new at PHP and having been trying to modify these two lines to work with four options instead of two

if ($this->db->VARS["allow_age"]==1) {
$AGE= ($this->age==20) ? "&nbsp;<img src=\"img/20.gif\" width=\"12\" height=\"12\">" : "&nbsp;<img src=\"img/30.gif\" width=\"12\" height=\"12\">";
}


if ($this->db->VARS["allow_age"]==1) {
$AGE = ($row['age']==20) ? "&nbsp;<img src=\"img/20.gif\" width=\"12\" height=\"12\">" : "&nbsp;<img src=\"img/30.gif\" width=\"12\" height=\"12\">";
}

I want this to display a different image if the variable is 20, 30, 40 or 50. and not just 20 and 30. I have tried everything I can think of. Any help. Thanks ahead of time

Posted: Thu Dec 04, 2003 12:38 am
by microthick
How about using the switch statement, rather than if.

read up here for examples:
http://ca2.php.net/manual/en/control-st ... switch.php

Posted: Thu Dec 04, 2003 12:38 am
by leebo
You may be better off using CASE than having 4 different ifs

$AGE= ($this->age==20);

Switch ( $AGE ) {

case "20":

do whatever

break;

case "30":

do whatever

break;

case "40":

do whatever

break;

case "50":

do whatever

break;

default:

echo "sorry no age selected";
}