[英]Error: mysqli_fetch_object() expects parameter 1 to be 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
mysqli_fetch_object() 期望参数 1 是 mysqli_result
Here is my PHP code:这是我的PHP代码:
<?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;
}
}
?> ?>
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.您的第一个查询应该是这样的,没有大括号,当然,直到您在表中显式地用大括号包裹了 id。
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其次,您正在执行多个查询,因此您可能想考虑检查您的查询是否正确执行(因为语法错误列不匹配表名不匹配的更多可能性):像
while($a...)
部分
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:第三,我看到您正在使用
pub_id
制作一个逗号分隔的列表,以便您可以在最后一个查询中将其作为参数提供,这是一个很长的镜头,为什么不为您的IN
子句使用子查询,如下所示:
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`;
The error you are stating translates to this: The query fails somehow, instead of running the mysqli_query($link, $sorgu);您所陈述的错误转化为:查询以某种方式失败,而不是运行 mysqli_query($link, $sorgu); line echo $sorgu, go to phpmyadmin and test your query, if it is bad, fix it in phpmyadmin until it works and set it up in the code correctly
行 echo $sorgu,转到 phpmyadmin 并测试您的查询,如果它是坏的,请在 phpmyadmin 中修复它,直到它可以正常工作并在代码中正确设置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.