$sql = "SELECT * from idea ORDER BY datetime DESC LIMIT 50;"; $result = $pdo->query($sql); if($result->rowCount() > 0 && !empty($result)) // line 6 { foreach ($result as $row) { $id = $row['id']; $title = $row['title']; $idea = $row['idea']; echo '<span class="idea" id="'.$id.'"><strong style="color: #0081C5">' . $title . "</strong> - " . $idea . ' <a class="delete" href="#">[Delete]</a></span>'; } }
一般如果你的sql语句查询出现错误时,没有进行$result 的判断,直接使用$result -> rowCount()会出现这种错误。