繁体   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