0)"; if ($j < sizeof($term) - 1) { $query .= " + "; } } $query .= ") by_".$places_to_search[$i]; } } $query .= " from recipe where 1=1"; # add all search terms to the query if (!empty($searchTerms)) { for ($i = 0; $i < sizeof($term); $i++) { $query .= " and ("; for ($j = 0; $j < sizeof($places_to_search); $j++) { $query .= "$places_to_search[$j] like '%".$term[$i]."%'"; if ($j < sizeof($places_to_search) - 1) { $query .= " or "; } } $query .= ")"; } } # add category to query if (!empty($cat)) { $query .= " and (find_in_set('$cat', category_1) > 0 or find_in_set('$cat', category_2) > 0)"; } # add time to query if (!empty($time) && $time != "0") { $query .= " and total_time <= $time"; } # add calories to query if (!empty($calories) && $calories != "0") { $query .= " and calories_from_fat <= $calories"; } # add main categories to query if (!empty($main_cat) && !in_array("all_categories", $main_cat)) { $query .= " and ("; for ($i = 0; $i < sizeof($main_cat); $i++) { $query .= "find_in_set('$main_cat[$i]', category_1) or find_in_set('$main_cat[$i]', category_2)"; if ($i < sizeof($main_cat)-1) { $query .= " or "; } } $query .= ")"; } # add cuisine categories to query if (!empty($cuisine_cat) && !in_array("all_categories", $cuisine_cat)) { $query .= " and ("; for ($i = 0; $i < sizeof($cuisine_cat); $i++) { $query .= "find_in_set('$cuisine_cat[$i]', category_1) or find_in_set('$cuisine_cat[$i]', category_2)"; if ($i < sizeof($cuisine_cat)-1) { $query .= " or "; } } $query .= ")"; } # add ingredient categories to query if (!empty($ingredient_cat) && !in_array("all_categories", $ingredient_cat)) { $query .= " and ("; for ($i = 0; $i < sizeof($ingredient_cat); $i++) { $query .= "find_in_set('$ingredient_cat[$i]', category_1) or find_in_set('$ingredient_cat[$i]', category_2)"; if ($i < sizeof($ingredient_cat)-1) { $query .= " or "; } } $query .= ")"; } if (isset($searchTerms)) { $query .= " order by by_".$places_to_search[0]." desc, by_".$places_to_search[1]." desc, by_".$places_to_search[2]." desc, name"; } else { $query .= " order by name"; } $db = mysql_pconnect("localhost", "recipearchive", "EmT8AYJG"); mysql_select_db("recipearchive", $db); $recipes = mysql_query($query, $db); } if (empty($pos)) { $pos = '0'; } if (empty($displaySize)) { $displaySize = 10; } ?> Quick recipe search at RecipeArchive.com
\n", mysql_num_rows($recipes)); $pagination = "\n"; # print pagination navigation echo $pagination; # default or prefered template if (empty($recipe_view)) { $recipe_view = 1; } $counter = 0; while ($recipe = mysql_fetch_array($recipes)) { if ($counter < $pos+$displaySize && $counter >= $pos) { $cals = $recipe["calories"]; # display lo-carb icon if necessary $lo_carb_image = ''; if ($recipe["nutrition_ok"] == 'y' && $recipe["carbohydrate"] <= 10) { $lo_carb_image = ''; } # display lo-fat icon if necessary $lo_fat_image = ''; if ($recipe["nutrition_ok"] == 'y' && $recipe["calories_from_fat"] <= 30) { $lo_fat_image = ''; } if ($recipe["nutrition_ok"] == 'n') $cals = 'n.a.'; printf("\n", ($counter+1), $recipe["recipe_id"], $lo_carb_image.$lo_fat_image, substr($recipe["comments"], 0, 200)."...", $cals, $recipe["total_time"]); } $counter++; } # print pagination navigation echo $pagination; echo "


Home | Recipe Search | Best Of | Dictionary | E-mail | About

\n"; ?>
Recipe Search
"; ?>
Enhanced Search
\n"; ?>
\n"; # print total number of results printf("
Total number of recipes found: %s
"; # print previous button if necessary if ($pos > 0) { $pagination .= "<< previous << "; } # print links to jump around in search results (paginate) $current_page = max(($pos-10*$displaySize)/10, 0); while ($current_page*$displaySize < mysql_num_rows($recipes) && $current_page*$displaySize < $pos+10*$displaySize) { if ($pos == $current_page*$displaySize) { $pagination .= "- ".($current_page+1)." -"; } else { $pagination .= " ".($current_page+1)." "; } $current_page++; } # print next button if necessary if ($pos < (mysql_num_rows($recipes)-$displaySize)) { $pagination .= " >> next >>"; } $pagination .= "
%s. ".$recipe["name"]."%s
%s; Calories: %s; Time: %s min.
\n"; } ?>