1

Hi I know other questions already have the answer to this but I don't understand. I've done lots of research and am still confused.

I have a table in my Mysql that I made with PHP My Admin it has three rows (I'll add to these) and 3 columns (id, name and price) I'd like to output the first rows name and id but I keep getting the error

Trying to get property of non-object;

<?php
 $db = new PDO('mysql:host=localhost;dbname=sitefiles;charset=utf8mb4','user', 'pass');           
 $sql = 'SELECT id, name FROM 1/1/16';
 $results = $db->query($sql);

 if ($results->num_rows > 0) {
    while($row = $results->fetch_assoc()) {
        echo "id: " . $row["id"]. " - Name: " . $row["name"];
    }
}
?>

How can I get rid of this error? Thank you :)

チーズパン
  • 2,752
  • 8
  • 42
  • 63
Oli B
  • 31
  • 6

1 Answers1

1

Your table name seems to be unusual. Try to use back-ticks to quote it:

$sql = 'SELECT id, name FROM `1/1/16`';
DevilaN
  • 1,317
  • 10
  • 21