When I try to get the value of "sold" and "featured" I get nothing. What am I doing wrong?
function list_products($sold = false, $featured = false) {
global $link;
$result = mysqli_query($link, "SELECT * FROM products product JOIN images image ON product.id = image.product_id WHERE product.main_image = image.id AND product.sold = $sold AND product.featured = $featured") or die(mysqli_error($link));
}
list_products(false, true);
Edit: If I try to echo $sold or $featured, they are blank. A 1 or 0 should show.
In your case you can give the arguments numeric values when calling the function (you want to use them as numeric in your query anyway).
Try:
function list_products($sold = 0, $featured = 0) {
global $link;
$result = mysqli_query($link, "SELECT * FROM products product JOIN images image ON product.id = image.product_id WHERE product.main_image = image.id AND product.sold = $sold AND product.featured = $featured") or die(mysqli_error($link));
}
list_products(0, 1);
Casting booleans to strings in PHP for a mysql query is not a good idea - true will become '1' and false will become ''. Use something like ($boolVar ? 1 : 0)
.