简体   繁体   中英

An If statement within an If statement

I'm checking to see if a check box has been checked on a search form. If that box has been checked, the value it outputs will be "No".

So if the value is "No", then I want to use an If statement to echo some PHP. The problem is, the PHP that I want to echo is an actual If statement itself.

Here's my code right now:

$showoutofstock = $_SESSION['showoutofstock']; 
if ( $showoutofstock == "No" ) {
} 
if($_product->isSaleable()): {
}

You can't really "echo some PHP". PHP is processed on the server-side, and the result is usually HTML that the browser client reads and displays.

It's not clear what you're actually trying to accomplish. Can you clarify a bit?

This might help though -- it's simply showing how to nest if statements, which may be all that you're asking for:

<?php
$showoutofstock = $_SESSION['showoutofstock']; 
if ( $showoutofstock == "No" ) {
    if($_product->isSaleable()) {
    }
} 
?>

you are closing your if before writing another if inside it

<?php
    $showoutofstock = $_SESSION['showoutofstock']; 
    if ( $showoutofstock == "No" ) { //main if clause start
        if($_product->isSaleable()) {//if clause inside main if start
        } //inner if clause ends here
    }//outer if clause ends here
?>

try it like this and yes you can check for the value of check box and can code accordingly inside that if clause

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM