简体   繁体   English

If语句中的If语句

[英]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. 因此,如果值是“ No”,那么我想使用If语句回显一些PHP。 The problem is, the PHP that I want to echo is an actual If statement itself. 问题是,我要回显的PHP本身就是一个实际的If语句。

Here's my code right now: 现在是我的代码:

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

You can't really "echo some PHP". 您不能真正“回显一些PHP”。 PHP is processed on the server-side, and the result is usually HTML that the browser client reads and displays. PHP是在服务器端处理的,结果通常是浏览器客户端读取和显示的HTML。

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: 不过,这可能会有所帮助-它只是显示如何嵌套if语句,这可能就是您要的全部内容:

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

you are closing your if before writing another if inside it 您要先关闭if,然后再在其中写入另一个if

<?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 像这样尝试,是的,您可以检查复选框的值,并可以在if子句中进行相应的编码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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