elixireu
elixireu

Reputation: 275

PHP if statement problem

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.

Upvotes: 0

Views: 686

Answers (5)

Pradeep Singh
Pradeep Singh

Reputation: 3634

You're missing a (

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

Upvotes: 0

elixireu
elixireu

Reputation: 275

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

Upvotes: 0

Sunandmoon
Sunandmoon

Reputation: 297

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

Upvotes: 0

Gumbo
Gumbo

Reputation: 655239

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){

Upvotes: 0

Konerak
Konerak

Reputation: 39763

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

Upvotes: 1

Related Questions