<?php include_once "models/Chef_Table.class.php"; include_once "models/Recipe_Table.class.php"; $chefTable = new Chef_Table($db); $recipeTable = new Recipe_Table($db); $isChefClicked = isset($_GET['chef_id']); $isRecipeClicked = isset($_GET['recipe_id']); if ($isChefClicked) { $chefId = $_GET['chef_id']; $chefData = $chefTable->getChef($chefId); $recipesByChef = $recipeTable->getAllByChefId($chefId); $displayPage = (include_once "views/single_chef.php"); } elseif ($isRecipeClicked) { $recipeId = $_GET['recipe_id']; $recipeData = $recipeTable->getRecipe($recipeId); $chefOfRecipe = $chefTable->getChefOfRecipe($recipeId); $displayPage = (include_once "views/single_recipe.php"); } else { $allChefs = $chefTable->getAllChefs(); $allRecipes = $recipeTable->getAllRecipes(); $displayPage = (include_once "views/all_chefs.php"); $displayPage .= (include_once "views/all_recipes.php"); } return $displayPage;
echo $page; $button = $_GET['submit']; $search = $_GET['search']; $dbInfo = "mysql:host=localhost;dbname=recipes"; $dbUser = "******"; $dbPassword = ""; $db = new PDO($dbInfo, $dbUser, $dbPassword); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); if (!$button) { echo "you didn't submit a keyword"; } else { if (strlen($search) <= 1) { echo "Search term too short"; } else { echo "You searched for <b> {$search} </b> <hr size='1' > </ br > "; $chefTable = new Chef_Table($db); $construct = $chefTable->joinChefsToRecipes($search); $rows = $construct->rowCount(); if ($rows == 0) { echo "Sorry, there are no matching result for <b> {$search} </b>. </br> </br>\n 1. Try more general words. for example: 'chicken' or 'meat loaf' </br>\n 2. Try different words with similar meaning </br>"; } else { echo "<h2>{$rows} results found!</h2>"; while ($run = $construct->fetchObject()) { $title = $run->title; $desc = $run->description; $first_name = $run->first_name; $last_name = $run->last_name; $recipe_id = $run->recipe_id; $chef_id = $run->chef_id; $recipe_url = "index.php?recipe_id={$recipe_id}"; $chef_url = "index.php?chef_id={$chef_id}";