PHP MySQL IF语句

I have the following IF/Else statement:

        if ( {$row['Stock']} > 0 ) {
        echo "<div class='col-md-2'>{$row['Stock']}</div>";
        } else {
            echo "<div class='col-md-2'>Out of Stock</div>";
        }

The {$row['Stock']} is a field in a MySQL statement. If I just echo the Stock quantity, it will echo the number. However, with my If/Else statement I get nothing on the page at all... is there something wrong with putting that MySQL statement in the PHP If/Else?

dta38159
dta38159 {$row['Stock']}是if语句中的无效语法,请尝试if($row['Stock']>0){而不是。
5 年多之前 回复

1个回答



想出来......必须从if比较中的$行中删除{}。</ p>
</ DIV>

展开原文

原文

Figured it out... had to remove the {} from around the $row in the if comparison.

dongqie2010
dongqie2010 变量已经是{}内的变量。 因此,没有必要尝试让php再次回应它,就好像你会像一个聪明的模板一样
5 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐