duandie0921 2014-04-14 12:13
浏览 190
已采纳

错误:mysqli_fetch_object()期望参数1为mysqli_result

I don't know what the problem is with this line or how to fix it, before was okay and now I'm getting this error:

mysqli_fetch_object() expects parameter 1 to be mysqli_result

Here is my PHP code:

<?php
}   
if($_GET['action']=="user_info")
    {

    $userid = $_GET['user_id'];

    $query = "SELECT * FROM user WHERE user_id ='{$userid}'";
    $result = mysqli_query($link, $query);
    $user = mysqli_fetch_object($result);

    $queryt = "SELECT * FROM user_title WHERE id='".$user->title."'";
    $resultt = mysqli_query($link, $queryt);
    $rowt = mysqli_fetch_object($resultt);
    $title = $rowt->name;

        $sorgu = "select * from pub_author where user_id='$userid'";
        $publications = mysqli_query($link, $sorgu);

        while($a = mysqli_fetch_object($publications))
    {
       $ids .= $a->pub_id . ',';
    }

       $ids = rtrim($ids,",");
   $sorgu2 = "select count(id) as total , year from publication where id IN ($ids)
       GROUP BY YEAR(`year`) order by `year` ";
   $publications2 = mysqli_query($link, $sorgu2);

       while($a2 = mysqli_fetch_object($publications2))
       {
          $mount = explode('-', $a2->year);
          $accyaz[$mount[0]] = $a2->total;
      }
  }

?>

  • 写回答

2条回答 默认 最新

  • dqwh1219 2014-04-14 12:30
    关注

    As far as your exact error is concerned one of your query is failing, the following steps might help. Ofcourse you question looks duplicate but here are some of the things that addresses your question

    Your first query should be like this, with no curly braces, ofcourse untill you have explicitly ids wrapped in curly braces in your table.

    SELECT * FROM user WHERE user_id ='$userid'
    

    Secondly you are executing multiple queries so you might wanna consider error checking if your query executes properly or not(because of syntax error columns mismatch table name mismatch many more possibilities): do error checking like this as for while($a...) part

    if ($result=mysqli_query($link, $sorgu);)
    {
      while($a=mysqli_fetch_object($result))
      {
        $ids .= $a->pub_id . ',';
      }
    
      $sorgu2 = "select count(id) as total , year from publication where id IN ($ids) GROUP BY YEAR(`year`) order by `year` ";
    
      //... Your further code
    }
    else
    {
        echo "Something went wrong while executing query :: $sorgu";
    }
    

    Third i see your are getting pub_id make a comma seperated list of it so that you can give it as a parameter in your last query which is a long shot, why not use sub query for you IN clause like this:

    SELECT 
        COUNT(id) as total, year 
        FROM publication 
        where id 
        IN (
            SELECT pub_id FROM pub_author WHERE user_id='$userid'
        ) 
        GROUP BY `year`
        order by `year`;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事: