【发布时间】:2014-09-06 22:31:49
【问题描述】:
我有一个 mysqli 查询,当我运行时返回以下错误。
致命错误:在第 57 行的 /home/tkweb/public_html/intermate.eu/companionsearch.php 中的非对象上调用成员函数 fetch_assoc()
我不确定为什么会出现此错误,因为我使用完全相同的代码运行查询,但实际查询参数和输出本身在另一个工作正常的页面上。
这是返回错误的代码:
$query2 = $con->query("SELECT * FROM journeys WHERE origin = $origin AND destination = $destination AND date = $date AND hour = $hour AND minute = $minute AND id != $id");
$count = mysqli_num_rows($query2);
if($count = 0) {
echo "Sorry, there are no other InterRailer's making this journey, try searching for individual legs if your journey contains more than one leg.";
}else{
$result = $con->query($query2);
while ( $row = $result->fetch_assoc() ) {
$companion[] = "<form id='companionresult' method='post' action='accountview.php'><input type='hidden' name='id' value='{$row['id']}'>{$row['firstname']}, {$row['age']}<br>{$row['nationality']}<br>Speaks: {$row['language1']}{$row['language2']}{$row['language3']}{$row['language4']}{$row['language5']}<br> <input id='submit3' type='submit' name='submit' value='View Profile'><br>";
foreach($companion as $info)
echo $info;
}
}
【问题讨论】:
-
学习使用
var_dump()。