$recipe_con = recipes_connect();
$sql = "SELECT category.name AS name, category.iconfilename AS cat_img, recipe.cat_id AS cat_id FROM recipe, category WHERE recipe.cat_id = category.id GROUP BY recipe.cat_id ORDER BY category.name";
$sel_query = $recipe_con->query($sql);
if (isset($tag)) {
$tg = urldecode($tag);
$sql = "SELECT recipe.*, category.iconfilename AS cat_img FROM recipe, category WHERE tags LIKE '%$tag%' AND recipe.cat_id = category.id GROUP BY recipe.cat_id ORDER BY category.name";
$sel_query = $recipe_con->query($sql);
}
if (isset($id)) {
$id = urldecode($id);
$sql = "SELECT recipe.*, category.iconfilename AS cat_img FROM recipe, category WHERE cat_id = '$id' AND recipe.cat_id = category.id GROUP BY recipe.cat_id";
$sel_query = $recipe_con->query($sql);
}
if (isset($cat_id)) {
$sql = "SELECT category.name AS cat_name, category.iconfilename AS cat_img, recipe.* FROM recipe, category WHERE recipe.cat_id = category.id AND recipe.cat_id = '$cat_id'";
$sel_query = $recipe_con->query($sql);
}
$first = "First";
if ($sel_query) {
$back_link = "
<< Back to Categories";
while($data = $sel_query->fetch_assoc()) {
$id = $data['id'];
$cat_id = $data['cat_id'];
$title = $data['title'];
$ingredients = $data['ingredients'];
$instructions = $data['instructions'];
$tags = $data['tags'];
$tags = get_all_tags($tags);
$name = $data['name'];
$cat_name = $data['cat_name'];
$iconfilename = $data['cat_img'];
$description = $ingredients;
$link = "recipe.php?id=$id";
if ($name != "") {
$title = $name;
$link = "recipe_list.php?cat_id=$cat_id";
$list .= "
";
} else {
$list .= "$back_link
";
}
if ($first == "First") {
$first = "";
$back_link = "";
}
}
if ($first == "First") {
$list .= "
";
}
if ($name != "") {
echo "Recipe Categories";
} else if ($tag != "") {
echo 'Recipes tagged "'.urldecode($tag).'"';
} else if ($cat_id) {
echo "Recipes from $cat_name";
} else {
echo "No Title";
}
?>