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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Morbius
Forum Newbie
Posts: 15
Joined: Sat Jul 27, 2002 12:10 am

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

Post 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?
Morbius
Forum Newbie
Posts: 15
Joined: Sat Jul 27, 2002 12:10 am

Post 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*
Morbius
Forum Newbie
Posts: 15
Joined: Sat Jul 27, 2002 12:10 am

Post by Morbius »

I think I figured it out... but still any help would be great.. or any idea's... or whatever
User avatar
PaTTeR
Forum Commoner
Posts: 56
Joined: Wed Jul 10, 2002 7:39 am
Location: Bulgaria
Contact:

Post 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';
}
?>
Post Reply