I am at a loss here. I cannot for the life of me figure out why I am getting the error.
Notice: Undefined index: price in /home/*****/public_html/newfinal/home_view.php on line 14
Notice: Undefined index: description in /home/****/public_html/newfinal/home_view.php on line 15
Here are the relevant code snippets:
PHP/ SQL
function get_product($product_id) {
global $db;
$query = "SELECT * FROM prjProducts p"
. " INNER JOIN prjCategories c"
. " ON p.categoryID = c.categoryID"
. " WHERE productID = :product_id";
try {
$stmt = $db->prepare($query);
$stmt->bindValue(':product_id', $product_id);
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$stmt->execute();
$result = $stmt->fetchAll();
$stmt->closeCursor();
return $result;
} catch (PDOException $ex) {
$error = $ex->getMessage();
echo $error;
}
}
PHP
// Set the featured product Id's in an array
$product_ids = array(3, 5, 10);
// Get an array of featured producst from the database
$products = array();
foreach ($product_ids as $product_id) {
$product = get_product($product_id);
$products[] = $product; // add the product to the array
}
HTML
<?php foreach ($products as $product) :
// Get product data
$price = $product['price'];
$description = $product['description'];
I have been banging my head at this one for a couple of hours now. I've tried to echo the arrays, and I can print out the arrays without issue. I'm sure it is some small formatting error that I am missing somewhere.