mysqli_query得到了我的学士学位,if的结果应该是10但是我得到的结果是15.是不是Bachelors没有输出为字符串?怎么做?
<?php $levelofeducation = mysqli_query($con,"SELECT levelofeducation AS value FROM retailmain WHERE id='1'");
if ($levelofeducation == "Elementary/H School"){echo "0";}
elseif ($levelofeducation == "JR Coll") {echo "5";}
elseif ($levelofeducation == "Bachelors"){echo "10";}
else {echo "15";}
?>
答案 0 :(得分:1)
看起来你期望从你的mysqli_query调用返回一个字符串,但它实际上返回一个mysqli_result对象(http://php.net/manual/en/mysqli.query.php)。
答案 1 :(得分:0)
您不是取结果,只是取道。使用mysqli_fetch_array()方法
获取结果 <?php
$q = mysqli_query($con,"SELECT levelofeducation AS value FROM retailmain WHERE id='1'");
$levelofeducation=mysqli_fetch_array($q);
if ($levelofeducation == "Elementary/H School"){echo "0";}
elseif ($levelofeducation == "JR Coll") {echo "5";}
elseif ($levelofeducation == "Bachelors"){echo "10";}
else {echo "15";}
?>