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

错误: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 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化