0

I am requesting this data from a database and it works fine,

<?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
                      }
                      ?>

Then when I do the same thing with a different table like this,

 $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']);

I get this error and I can not figure out why...

Fatal error: Call to a member function fetch() on a non-object in 

The error is on the line with the while loop

I found this thread that evidently explains the same issue but I don't understand why or the solution.

Stack Overflow Q&A

Note This ORDER BY created_time DESC is a timestamp

Community
  • 1
  • 1
wuno
  • 9,547
  • 19
  • 96
  • 180

0 Answers0