I need to have an if statement within a query? I have a query for a listing with dishes for a restaurant. Everythig is quite straightforward:
$menu_id = filter_input(INPUT_GET, 'menu_id', FILTER_SANITIZE_NUMBER_INT);
$language_abbr = filter_input(INPUT_GET, 'lang', FILTER_SANITIZE_STRING);
$menulisting = $pdo->query("SELECT language_abbr, menu_item_number, menu_item, menu_item_description, menu_item_price, menu_item_price_2
FROM afhaal_items
WHERE menu_kaart_id = $menu_id
AND language_abbr = '$language_abbr' ");
Nothing complicated. What I need though, is that if the passed menu_id is 10 to have an extra field, an INNER JOIN and a GROUP BY added to the query. Something like:
if ( $menu_id == 10 ){
$menulisting .= ",sushi_category INNER JOIN sushi_categories ON afhaal_items.sushi_categorry_id = sushi_categories.sushi_categorry_id GROUP BY sushi_category";
}
I need that extra field only with menu_id 10 (Sushi) because that category is categorized within itself (e.a. Sushi maki, Nigri Sushi etc). Which I need as a subheader in the output, but only for that menu_id.
Any help would be highly appreciated!
Edit you can see an example of the category I need this for right here and then clcik on sushi