简体   繁体   English

查询未返回结果

[英]Query returning no results

This is the link the sends the $Row[pk_tId] to javascript: 这是将$ 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>";

This is the javascript that sends $Row[pk_tId] as groupId to the modal (on the same page): 这是将$ Row [pk_tId]作为groupId发送到模态的JavaScript(在同一页面上):

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

This is the input field inside the modal that prints groupId: 这是打印groupId的模式内部的输入字段:

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

I echo out the $id: 我回显$ id:

   echo "Your id is: " . $id;

But when I try to select the $id to pull the record out of the database, it returns no records. 但是,当我尝试选择$ id将记录从数据库中拉出时,它不返回任何记录。 The record is there. 记录在那里。 Here is the statement: 这是声明:

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

The only thing I get is "No results." 我唯一得到的是“没有结果”。 I have a steady connection to the database. 我与数据库的连接稳定。 Why isn't this statement returning anything? 为什么该语句不返回任何内容? What am I missing? 我想念什么? Please help. 请帮忙。

You are not doing the actual query: 您没有在进行实际的查询:

   $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";
    }

The reason that the mysql_num_rows function still makes the condition, is because it returns false. mysql_num_rows函数仍然产生条件的原因是因为它返回false。 0 and false are the same if you compare with two equal signs. 如果将两个相等的符号进行比较,则0和false相同。 If you would have done this: 如果您会这样做:

   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)

too clearify a bit more: 太清楚了一点:

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)

You are not executing the query at any point: 您在任何时候都不会执行查询:

$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 is deprecated now btw (i've seen people's head get ripped off on this site for sill using it haha!) mysql_query现在已被弃用(我见过人们在这个网站上抢了它的头,以使用它为基石哈哈!)

I saw your other question from above ;-) 我从上面看到了您的其他问题;-)

$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