I have below query:
//Get the data
$stmt = $dbh->prepare("
SELECT t1.*, t2.*
FROM softbox_bookings_data t1
LEFT JOIN softbox_bookings t2 ON t1.booking_id = t2.id
WHERE t2.id=:id
GROUP BY t1.model
ORDER BY t2.time ASC");
$stmt->bindParam(":id", $_GET["id"]);
$stmt->execute();
$data = $stmt->fetchAll();
Now I want to be able to use above query multiple times.
First I want to just echo out a variable:
echo $data["name"]; //Returns nothing
Then further down the page, I want to loop the data:
foreach($data as $row){
echo $row["name"]; //Successfully echoes out the name from the database.
}
How come I can't use the echo $data["name"]
variable and the foreach()
statement to run through the data?