$query = "SELECT unitstat FROM tblunits where unitid='VDMRB1001'" ;
$result=mysql_query($query);
//unitstat is the field i'm trying to call
$field=("unitstat"); //is this correct??
while($unitstat = mysql_fetch_field($result)) //is this correct??
if ($unitstat=="SOLD")
echo "THIS UNIT IS SOLD!";
else
echo "THIS UNIT IS FOR SALE!";
答案 0 :(得分:1)
mysql_fetch_field
返回包含字段信息的对象。要获取sql查询结果,您应该使用mysql_fetch_row
或mysql_fetch_assoc
之类的内容。
最好的方法是检查php manual。
答案 1 :(得分:1)
这应该这样做:
$query = "SELECT unitstat FROM tblunits where unitid='VDMRB1001'" ;
$result=mysql_query($query);
while($row = mysql_fetch_array($result))
{
$unitstat = $row['unitstat'];
if ($unitstat=="SOLD")
echo "THIS UNIT IS SOLD!";
else
echo "THIS UNIT IS FOR SALE!";
}
答案 2 :(得分:0)
$query = "SELECT unitstat FROM tblunits where unitid='VDMRB1001'" ;
$result=mysql_query($query);
while ($row = mysql_fetch_assoc($result)) {
echo 'THIS UNIT IS ' . ($row['unitstat'] == 'SOLD') ? 'SOLD!' : 'FOR SALE!';
}
答案 3 :(得分:0)
试试这个:
$query = "SELECT unitstat FROM tblunits where unitid='VDMRB1001'";
$result = mysql_query($query) or die(mysql_error());
while(list($unitstat) = mysql_fetch_array($result))
{
if ($unitstat == "SOLD")
echo "THIS UNIT IS SOLD!";
else
echo "THIS UNIT IS FOR SALE!";
}