我从数据库请求此数据并且工作正常,
<?php
$stmt = $con->query('SELECT * FROM blogData ORDER BY id DESC');
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$title = htmlspecialchars($row['title']);
$content = htmlspecialchars($row['content']);
$category = htmlspecialchars($row['category']);
?>
<div class="features">
<div class="box"><img src="Developer/common-files/icons/time@2x.png" width="100" height="100" alt="Wuno Inc.">
<h6><?php echo htmlspecialchars($category); ?> - <?php echo htmlspecialchars($title); ?></h6>
<p><?php echo htmlspecialchars($content); ?></p>
</div>
</div>
<?php
}
?>
然后当我用这样的不同表做同样的事情时,
$stmt = $con->query('SELECT * FROM taggePlaces ORDER BY created_time DESC');
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$id = htmlspecialchars($row['id']);
$created_time = htmlspecialchars($row['created_time']);
$place_id = htmlspecialchars($row['place_id']);
$city = htmlspecialchars($row['city']);
$country = htmlspecialchars($row['country']);
$latitude = htmlspecialchars($row['latitude']);
$longitude = htmlspecialchars($row['longitude']);
$state = htmlspecialchars($row['state']);
$street = htmlspecialchars($row['street']);
$zip = htmlspecialchars($row['zip']);
$name = htmlspecialchars($row['name']);
我收到此错误,我无法弄清楚原因......
Fatal error: Call to a member function fetch() on a non-object in
错误在while loop
我发现这个帖子显然解释了同样的问题,但我不明白为什么或解决方案。
Note
此ORDER BY created_time DESC
是时间戳