Page 1 of 1

Newbie PHP Programmer needs help with if()/else() statements

Posted: Sun Jul 28, 2002 4:49 am
by Morbius
How many times can the if statement be repeated... this is my current script that comes from as form... Ill post first the form handle and then the script...


Form:

<select name="race"><option value="human">Human</option>
<option value="shadow">Shadow Wrath</option>
<option value="arkerian">Arkerian</option>
<option value="jiana">Jiana</option>
<option value="terrianown">Terrianown</option>
</select>

PHP:

<?php
if($race = "human")
{
echo("Human");
}
if($race = "shadow")
{
echo("Shadow Wraith");
}
if($race = "arkerian")
{
echo("Arkerian");
}
if($race == "jiana")
{
echo("Jiana"};
}
if($race == "terrianown")
{
echo("Terrianown");
}
?>


Can anyone tell me, or show me what I am doing wrong?

Posted: Sun Jul 28, 2002 5:03 am
by Morbius
<span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span> I should just use an array shouldn't I??????
But how.. *ponders*

Posted: Sun Jul 28, 2002 5:10 am
by Morbius
I think I figured it out... but still any help would be great.. or any idea's... or whatever

Posted: Sun Jul 28, 2002 5:14 am
by PaTTeR
So,
you can repeat 'if' statement unlimited, but it's easy to use 'switch' statement.


Form
[\b]

Code: Select all

<select name="race"><option value="human">Human</option>
<option value="shadow">Shadow Wrath</option>
<option value="arkerian">Arkerian</option>
<option value="jiana">Jiana</option>
<option value="terrianown">Terrianown</option>
</select> 
&#1111;\code]


&#1111;b]
PHP script
&#1111;\b\]

&#1111;code]
<?php
switch ($race) {
   case 'human' :
        echo 'Human';
        break;
    case 'shadow' :
        echo 'Shadow';
        break;
    case 'arkerian' :
        echo 'Arkerian';
        break;    case 'jiana' :
        echo 'Jiana';
        break;
    case 'terrianown' :
        echo 'Terrianown':
        break;
     default :
        echo 'Not in list';
}
?>