簡體   English   中英

查詢未返回結果

[英]Query returning no results

這是將$ Row [pk_tId]發送到javascript的鏈接:

    <a class=\"open-EditRow btn btn-primary btn-mini\" data-toggle=\"modal\" href=\"#myEditModal\" data-id=\"".$Row[pk_tId]."\" title=\"Edit this row\" \">Delete/Edit</a></td>";

這是將$ Row [pk_tId]作為groupId發送到模態的JavaScript(在同一頁面上):

   $(document).on("click", ".open-EditRow", function () {
     var myGroupId = $(this).data('id');
     $(".modal-body #groupId").val( myGroupId );
   });

這是打印groupId的模式內部的輸入字段:

   $id = "<input type=\"text\" name=\"groupId\" id=\"groupId\" value=\"\" />";

我回顯$ id:

   echo "Your id is: " . $id;

但是,當我嘗試選擇$ id將記錄從數據庫中拉出時,它不返回任何記錄。 記錄在那里。 這是聲明:

   $q = "SELECT * FROM restable WHERE pk_tId == '" . $id . "'";
   if (mysql_num_rows($q) == 0){
        echo "No results";
    }

我唯一得到的是“沒有結果”。 我與數據庫的連接穩定。 為什么該語句不返回任何內容? 我想念什么? 請幫忙。

您沒有在進行實際的查詢:

   $q = "SELECT * FROM restable WHERE pk_tId = '" . $id . "'";
   $query = mysql_query($q); // <- you forgot this line, $q is only a string
   if (mysql_num_rows($query ) === 0){
        echo "No results";
    }

mysql_num_rows函數仍然產生條件的原因是因為它返回false。 如果將兩個相等的符號進行比較,則0和false相同。 如果您會這樣做:

   if (mysql_num_rows($query ) === 0){ // This only fires when the functions return INT 0
   if (mysql_num_rows($query ) === false){ // This only fires when the function returns false (on error)

太清楚了一點:

1==true   -> true
1===true  => false  (not the same type)
0==false  -> true
0===false -> false  (not the same type)
1=='1'    -> true
1==='1'   -> false (not the same type)
false=='false'  -> true
false==='false' -> false (not the same type)

您在任何時候都不會執行查詢:

$q = "SELECT * FROM restable WHERE pk_tId == '" . $id . "'";
$query = mysql_query($sql); // <-----------missing from your code
if (mysql_num_rows($query) == 0){ // <------notice the difference
    echo "No results";
}

mysql_query現在已被棄用(我見過人們在這個網站上搶了它的頭,以使用它為基石哈哈!)

我從上面看到了您的其他問題;-)

$q = "SELECT * FROM restable WHERE pk_tId == '" . $id . "'";
$q = "SELECT COLUMN_NAME FROM restable WHERE pk_tId == '" . $id . "'"; // <--works with example below
$query = mysql_query($sql); // <-----------missing from your code
if (mysql_num_rows($query) == 0){ // <------notice the difference
    while($row = mysql_fetch_assoc($query)){
        echo '<input type="text" value="'.$row['COLUMN_NAME'].'">';
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM