I've created a function that makes a query of a database table and managed to use the results in another page where the function is called.
Is this approach good?
function cart_list($db, $user){
$stmt = $db->prepare("
SELECT
o.username,
o.quantity,
p.description,
p.product_name,
FROM
orders as o
INNER JOIN
products as p
ON
p.product_id = o.product_id
INNER JOIN
users as u
ON
o.username = u.username
WHERE
o.username ='$user'
AND
o.checkout ='0'");
return $stmt;
}
In the file where I called the function, I used:
$stmt = cart_list($db, $user);
$stmt->bind_result(
$username,
$quantity,
$description,
$product_name);
$stmt->execute();
while($stmt->fetch()){
echo $product_name;
}