0

I have a MySql database with the var 'mls', which either has an entry of 0 or 1.

I am trying to use an If statement to display text depending on the mls var.

The data is being pulled from the datbase ok becasue I can use an 'echo' to dispaly the entry of the 'mls'. The problem is it is just going straight to the else statement and showing the 'else' data, here is the code...

<? echo ucwords($res['mls']); ?>
   <? if ($res['mls']) == 0)){

    echo $lang['rental'];   
}else
echo $lang['purchase'];
    ?>

Any help would be great.

1
  • Any reason, why you're ucword-ing a number? Commented Dec 10, 2010 at 18:52

5 Answers 5

1

It goes to the else because your if is wrong (count the parentheses)

 <? if ($res['mls']) == 0)){

Does the same as

<? if (0){

Which is false.

Fix:

 <? if ($res['mls'] == 0){

But do count your parentheses else where in the code ;)

Complete correct code:

<? 
 echo ucwords($res['mls']);
 if ($res['mls'] == 0)){
  echo $lang['rental'];   
 }
 else {
  echo $lang['purchase'];
 }
?>
Sign up to request clarification or add additional context in comments.

Comments

0

There is a syntax error in this line:

<? if ($res['mls']) == 0)){
                  ^

The marked closing parenthesis is also the closing parenthesis of the if statement syntax. Remove it and also the closing parenthesis right behind the 0:

<? if ($res['mls'] == 0){

Comments

0
<? echo ucwords($res['mls']); ?>
<? if ($res['mls'] == 0){
    echo $lang['rental'];   
}else{
     echo $lang['purchase'];
?>

Comments

0

Many Thanks for your help, it was the closing parenthesis of the if statement syntax and also the closing parenthesis right behind the 0:

Its now working ...

<? echo ucwords($res['mls']); ?>
   <? if ($res['mls'] == 0){

    echo $lang['rental'];   
}else
echo $lang['purchase'];
    ?>

Thanks

Comments

0

You're missing a (

<? if ($res['mls'] == 0)){

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.