2014-12-02 35 views
-3

mysqli_query讓我學士學位,如果應該是10的結果,但我得到的結果15.是不是作爲字符串輸出學士學位?這個怎麼做?錯誤的結果在PHP

<?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";} 
     ?> 
+2

您需要循環查詢的結果,然後進行比較。 – 2014-12-02 20:48:18

+2

您需要查看示例並瞭解如何從查詢結果中獲取行,然後瞭解如何訪問行中的值。 – AbraCadaver 2014-12-02 20:48:35

+3

,你正在分配$ levelofeducation1,但試圖訪問$ levelofeducation - 這就是爲什麼你總是得到15,因爲它總是擊中else。 – 2014-12-02 20:48:45

回答

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";} 
    ?> 
+0

這仍然是返回15而不是10 .. – Andrew 2014-12-02 21:05:42

+0

你現在可以在 之後發出回聲$ levelofeducation = mysqli_fetch_array($ q); echo $ levelofeducation; – 2014-12-02 21:07:57

+0

那就是 - > 注意:第8行的C:\ xampp \ htdocs \ retailv.php中的數組到字符串的轉換 數組 – Andrew 2014-12-02 21:15:36