I have a simple table called people with three fields. Eventually I'd like to use the results of a SELECT query to populate the default values of a form, but for now I'm just trying to echo the results of the query. I've tried lots of things and now I'm getting an 'array to string conversion' error on line 11 (the echo). Here's what I'm trying:
<?php
include 'connect_db.php';
$stmt = $conn->query("SELECT * FROM people");
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($results as $key => $value) {
echo $key . ':' . $value . '<br>';
}
?>
What am I doing wrong?
$keyis just index number and$valueis an array representing database row. You can't echo array like that.Array ( [first_name] => Bob [last_name] => Smith [name_id] => 2 ) 1. (An aside--what is the1at the end?) But I'm still not clear on what to do about it. Do I need to specifically refer to each column by name?