0

I've an if else statement.

IF the recordset is not empty AND if a specific record is greater then 0 then show.....

<?php if ($totalRows_bigimgRec > 0) {  ?>
<?php
if(( $row_bigimgRec['disable_big_image'] ) > (0)) {
?>

The above is the code I have. Yes it came from dreamweaver, but I want to have it as one statement.

I have tried hundreds of different ways to no avail.

<?php if ($totalRows_bigimgRec > 0) {  
AND
if(( $row_bigimgRec['disable_big_image'] ) > (0)) {
?>

the 2 conditions have to be met before I can show some thing other further down my page.

Can anyone advise as to how to get this working, I have read many manuals but am new to php and cannot get my head around.

4
  • Check your brackets if (($totalRows_bigimgRec > 0) AND ($row_bigimgRec['disable_big_image'] > 0)) { Commented Mar 10, 2015 at 13:01
  • if ($totalRows_bigimgRec > 0 && $row_bigimgRec['disable_big_image'] > 0) { Commented Mar 10, 2015 at 13:04
  • Brilliant thank you very much. If i win the lottery on Friday I will buy you all a second hand car, each that is. Commented Mar 10, 2015 at 13:13
  • It's better to give both of them half a car, @Seemore - much less likely to have an accident! Commented Mar 10, 2015 at 14:55

4 Answers 4

1

something like this..

 if ($totalRows_bigimgRec > 0 && $row_bigimgRec['disable_big_image'] > 0) {
      // do something
 }
Sign up to request clarification or add additional context in comments.

1 Comment

While this code snippet may solve the question, including an explanation really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion.
1

As you can see at http://php.net/manual/en/language.operators.logical.php

You should $c = ($a and $b);

So within your IF-statement you want both to be TRUE, hence:

<?php if( ($totalRows_bigimgRec > 0) and ($row_bigimgRec['disable_big_image']  > 0 )) { 
//code to be run when the condition is met
} ?>

Alternatively you can use && instead of AND

Comments

1

You can use && where IF Statement can check both conditions are TRUE

<?php
    if (!empty($totalRows_bigimgRec) && $row_bigimgRec['disable_big_image']  > 0){
        // rest of your code
    }
?>

I saw some extra parenthesis as well which PHP will warning with syntax error. Remove then too.

Hope it helps you.

Comments

0

You should use something like:

<?php if(!empty($whatever) && $othervariable > 0){ ?>write html <?php } ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.