Reputation: 9855
I'm new to PHP and very new to PDO. Everyone's been telling me to learn.
I've manage to establish a connection to my database, and I'm trying to return my results and wrap each row in a DIV
, but it's only returning an array with all the column titles.
I currently have:
$sql = "SELECT * FROM users";
$q = $conn->query($sql) or die("failed!");
while($r = $q->fetchAll(PDO::FETCH_ASSOC)){
print_r($r);
}
Can anybody point me in the right direction or give me some useful sites that can help?
Upvotes: 0
Views: 3909
Reputation: 61
$stmt = $conn->prepare("SELECT * FROM users");
$stmt->execute();
foreach( $stmt as $row )
{
echo "<div>" . $row['column'] . "</div>"
}
Upvotes: 2
Reputation: 9855
It was easier for me to do this...
while($r = $q->fetch(PDO::FETCH_LAZY)){
echo '<div>';
echo $r['id'];
echo $r['first_name'];
echo $r['surname'];
echo $r['hometown'];
echo $r['facebook'];
echo '</div>';
}
Upvotes: 0