2016-10-24 115 views
-2

我無法返回sql行的值,我的SQL請求在控制檯上運行良好,但無法返回它的一行與我的代碼,任何幫助?謝謝 !SQL找不到任何值

<?php 
require_once 'sql.php'; 
$sqlConnexion = new mysqli($hn,$un,$pw,$db); 
if($sqlConnexion->connect_error){ 
die ('Soucis de connexion SQL');} 

$date = date("d/m/y G:i:s"); 
if(isset($_POST['zoneDeText'])){ 
$area = $_POST['zoneDeText']; 

    $queryone= "SELECT SortieTraitée FROM entry WHERE entréesUtilisateurs=?"; 
    $instruction = $sqlConnexion->prepare($queryone); 
    if(!$instruction->prepare($queryone)){ 
     echo "$instruction->errno"; 

    }else{ 
    $instruction->bind_param('s', $area); 
    $instruction->execute(); 
    $result = $instruction->get_result(); 

    while ($row = $result->fetch_array(MYSQLI_NUM)){ 
    foreach ($row as $out){ 
    if($out == $area){ 
     echo $out; 
    }elseif($out != $area){ 
     echo 'Still not found'; 
      } 
     } 
    } 
     $instruction->close(); 
} 
?> 
+2

'選擇entréesUtilisateurs=? FROM entry'不能顯示正確的結果。你的'where'條款發生了什麼? –

+0

* nothing *標籤專指VB.Net'nothing'的值。這裏的標籤有特定的含義。請不要隨意添加它們,因爲它們看起來很熟悉。在使用它之前閱讀標籤說明以確保它是合適的。如果您仍不確定,請將其關閉,如有需要,此處有人會爲您添加它。在詢問代碼相關的問題時,爲您使用的語言添加標籤也很重要,您還沒有這樣做。請[編輯]這樣做。 –

回答

0

其實你不顯示任何信息,你只要return的價值,這是沒有意義的,除非你的代碼是一個函數裏面。

if($out == $area){ 
    return $out; 
} 

文檔http://php.net/return說:

如果返回從主腳本文件中調用,那麼腳本執行結束。

除非上面顯示的代碼已經包含在另一個PHP腳本中,這意味着它只會結束腳本並不輸出任何內容。

你的腳本還有其他幾個令人困惑的事情,但上面可能是你所問的問題的直接責任人。


以下是我可能會這樣寫代碼:

if (isset($_POST['zoneDeText'])) { 
    $area = $_POST['zoneDeText']; 

    $queryone = "SELECT SortieTraitée FROM entry WHERE entréesUtilisateurs=?"; 
    $instruction = $sqlConnexion->prepare($queryone); 

    // if the prepare fails, it is false 
    if ($instruction === false) { 
     // false is not an object, it has no error attribute 
     // the error is an attribute of the connection 
     die($sqlConnexion->error); 
    } 

    $instruction->bind_param('s', $area); 
    $instruction->execute(); 
    $result = $instruction->get_result(); 

    // if there are zero rows in the result, the while loop 
    // will finish before it starts, so there will be no output 
    // so first check for a result of zero rows in the result 
    if ($result->num_rows == 0) { 
    echo("Found zero rows"); 
    } else { 
    while ($row = $result->fetch_assoc()) { 
     echo $row["SortieTraitée"]; 
    } 
    } 
    $instruction->close(); 
} 
+0

謝謝,是的,因爲你可以看到我是一個初學者=)是的回報是一個可怕的錯誤:(但即使我取代它讓我們說「echo $ out」它不會告訴我什麼任何想法爲什麼?謝謝=) – user2690397

+0

@ user2690397看到上面的示例代碼 –

+0

它的工作,謝謝 – user2690397