PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
function get_products() {
global $conn;
$query = 'SELECT * FROM products
ORDER BY product_id';
$products = $conn->query($query);
return $products;
}
function get_product($product_id) {
global $conn;
$query = "SELECT * FROM products
WHERE productID = '$product_id'";
$product = $conn->query($query);
$product = $product->fetch();
return $product;
}
Without being able to see all of the code, I would suggest back tracing through the code and do do var_dumps in the code from this section back to where you loaded the data to see where you "loose it". It could be as simple as what actually calls this code is a function, and $products isn't in scope for it.
On a different topic, you will probably want to watch this code: