I have a 2 column SQL table as follows:
Product Price
Drill 20
Hammer 15
Screwdriver 5
Screws 2
Nuts 3
Bolts 6
I eventually want to embed a PHP array into a Google charts script. But first, how do I pass my SQL query into an array? My code below doesn't seem to work.
Here's my code, I'm just placing the SQL results into a table for testing purposes:
<?php
$page_title = 'Exercise 1';
require_once('mysql_connect.php');
try{
$sql = "SELECT product, price FROM 'inventory'";
echo "<table border ='0'>
<tr>
<th>Product</th>
<th>Price</th>
</tr>";
$statement = $db->query($query);
while($row = $statement->fetch(PDO::FETCH_ASSOC)){
// create arrays and pass in values
$product = $row['product'];
$price = $row['price'];
echo "<tr>";
echo "<td>" .$product ."</td>";
echo "<td>" .$price ."</td>";
echo "</tr>";
} // End our while loop
echo "</table>";
}
catch(PDOException $e){
$message = '<p>Error</p><p>' . $e->getMessage() . '</p>';
}
?>
Thanks