As bradgrafelman said, your code is just printing out the SQL Query, not the results....
I'm assuming you want to print out the results from the query.
Use fetch()if you are using prepared statements, which you aren't in this example.
Try one of these:
<?php
foreach ($contents as $id=>$qty) {
$sql = 'SELECT * FROM products WHERE id = '.$id;
$result = $db->query($sql);
$row = $result->fetch_array();
extract($row);
echo $columnName1;
echo $columnName2;
echo $columnName3;
}
?>
Or ...
<?php
foreach ($contents as $id=>$qty) {
$sql = 'SELECT * FROM products WHERE id = '.$id;
$result = $db->query($sql);
$row = $result->fetch_array();
echo $row['columnName1'];
echo $row['columnName2'];
echo $row['columnName3'];
}
?>
Or a number of others depending on your style and needs....
Note: It is typically a bad practice to use "SELECT *" in your queries.. instead, specify your column names in your query.