开发者

PHP if statement problem

I have a M开发者_如何学编程ySql 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.


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


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


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


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


You're missing a (

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜