【问题标题】:resource id # 53 error in mysql [duplicate]mysql中的资源ID#53错误[重复]
【发布时间】:2012-09-27 06:08:37
【问题描述】:

可能重复:
How do i “echo” a “Resource id #6” from a MySql response in PHP?

大家好,当我尝试在 PHP 中运行我的代码时出现错误。 它在我的屏幕上显示资源 id #53。我只想计算我的一个领域的总数,但我遇到了这个错误。下面是我的代码:

$last_points = mysql_insert_id();
//echo $last_points , display like 12... no error
$fkid = $last_points;   // no error....
$sql = "SELECT COUNT(*) FROM downline WHERE fkmember = {$fkid}";
$execute = mysql_query($sql) or die (mysql_error());
echo $execute; //display error why?

请帮帮我。我想这是我的问题。

【问题讨论】:

    标签: php mysql database codeigniter


    【解决方案1】:

    首先,resource id #53 不是错误。您显示的是resource,而不是查询的输出。

    要显示输出,请使用:

    $last_points = mysql_insert_id();
    //echo $last_points , display like 12... no error
    $fkid = $last_points;   // no error....
    $sql = "SELECT COUNT(*) FROM downline WHERE fkmember = {$fkid}";
    $execute = mysql_query($sql) or die (mysql_error());
    print_r(mysql_fetch_array($execute)); //display error why?
    

    其次,mysql_* 函数已被弃用。您应该相应地学习和使用mysqliPDO 库。

    【讨论】:

    • 我得到了 Array ( [0] => 0 [COUNT(*)] => 0 ) 表示没有数据对吗?
    • 表示没有结果WHERE fkmember = {$fkid}
    • 我在我的表中查找了它,有 23 条记录。我怎样才能得到记录总数?
    【解决方案2】:

    不要尝试echo 一个结果集(因为mysql_query 而收到)这样做:

    print_r( mysql_fetch_array($execute) );
    

    【讨论】:

      【解决方案3】:

      $execute 是一个数组,所以你需要在 echo 中打印出来

      print_r($execute);
      

      【讨论】:

        【解决方案4】:

        通过codeigniter方式

        在模型中:

        function getCount($fkid)
                {
                    $Qry = "SELECT * FROM downline WHERE fkmember = $fkid};
                    $query = $this->db->query($Qry);
                    return $query->num_rows();
                }
        

        在控制器中:

        echo $Count = $this->modelname->getCount($id);
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2014-04-06
          • 2017-06-29
          • 2014-11-18
          • 1970-01-01
          • 2017-04-18
          • 2011-10-31
          • 2013-10-16
          相关资源
          最近更新 更多