Hi there,
I am trying to populate a page with multiple rows from a mySQL database.
To grab the data, I am using:
for ($i=1; $i < 5; $i++) {
$query = 'SELECT * FROM table WHERE column = ?';
$statement = $mySQL_con->prepare($query);
try {
$statement->execute(array($i));
}
catch (PDOException $error) {
echo 'Sorry, we failed to load this page: ' . $error->getMessage();
}
$row = $statement->fetch();
$results[] = $row;
}
That creates a mutil-dimensional array. However, when I try to access that data things go a bit weird.
For example,print_r($results[2][name]);
should output the name from the third row I grabbed using the mySQL query (third because PRIMARY KEY > 0). Instead, I get the error message: "Use of undefined constant blog_id - assumed 'blog_id'"
The strange thing is that directly underneath that error message, I get the name value from the array I wanted.