如果必须,尝试检查通常为0或1的值可以使用NULL,但不愿意。即使价值是" 1"仍然开始" 0"回声。为什么呢?
<?php
$VIN = "76543212345678654";
$result = mysql_query("SELECT 'SOLD' from tblinventory WHERE 'VIN' = '$VIN'");
if ('SOLD' !== NULL) {echo ("1");}else{echo ("0");}
?>
答案 0 :(得分:3)
试试此代码
$result=mysql_query("SELECT SOLD from tblinventory WHERE VIN = '$VIN'");
$result_array=mysql_fetch_array($result);
if ($result_array['SOLD'] != NULL)
{
echo ("1");
}
else
{
echo ("0");
}
答案 1 :(得分:2)
删除单引号(')
。试试这样的事情
$VIN = "76543212345678654";
$result = mysql_query("SELECT SOLD from tblinventory WHERE VIN = '$VIN'");
$row = mysql_fetch_assoc($result);
if (isset($row['SOLD']) && $row['SOLD']) {
echo ("1");
}else{
echo ("0");
}
答案 2 :(得分:1)
您无法选择&#39; SOLD&#39;列,使用SOLD
和WHERE&#39; VIN&#39;进行更改。 =&#39; $ VIN&#39;也是......用WHERE VIN
=&#39; $ VIN&#39;
答案 3 :(得分:0)
如果$ result [“SOLD”] == 0然后没有卖出,如果$ result [“SOLD”]&gt;我宁愿数VIN并做数学0然后卖出..或者只是回显$ result [“SOLD”]
("SELECT COUNT(VIN) SOLD WHERE WHERE VIN = '$VIN'");