<?php require_once "db.php"; $return_url = "index.php"; if (isset($_GET['return'])) { $return_url = $_GET['return']; } header("location:{$return_url}"); if (!isset($_POST['username'])) { header("location:{$return_url}"); } else { $username = $_POST['username']; $password = $_POST['password']; $connection = milf_connect(); $query = "SELECT * FROM User WHERE username='******' AND password='******'"; $result = milf_query($query, $connection); mysql_close($connection); if (!$result) { die("Database access failed: " . mysql_error()); } elseif (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); session_start(); $_SESSION['username'] = $row['username']; $_SESSION['user_id'] = $row['id']; header("location:{$return_url}"); } else { header("location:{$return_url}"); } }
$result = milf_query($query, $connection); } else { $query = "SELECT Meal.id, title, description, img, ingredients, AVG(rating) as rating\n\t\t\t\tFROM Meal LEFT JOIN Ate ON Meal.id=Ate.meal_id\n\t\t\t\tWHERE calories BETWEEN {$cal_min} AND {$cal_max}\n\t\t\t\t{$cuisine}\n\t\t\t\tGROUP BY Meal.id\n\t\t\t\tLIMIT {$first}, {$limit}"; $result = milf_query($query, $connection); } if (!mysql_num_rows($result)) { echo "<h2>No Results</h2>"; } else { echo "<br /><br />"; while ($meal = mysql_fetch_assoc($result)) { $rating = "unrated"; if ($meal['rating'] != 0) { $rating = number_format($meal['rating'], 2); } $query2 = "SELECT ingredient FROM Ingredients WHERE meal_id={$meal['id']}"; $result2 = milf_query($query2, $connection); $ing_list = array(); while ($i = mysql_fetch_array($result2)) { $ing_list[] = $i[0]; } echo "<div id='result' style='clear:left; height:85px'>"; printf("<img src='%s' width='100' height='100' style='float:left'>", $meal['img']); echo "<div id='resultInfo' style='margin-left:110px'>"; printf("<a href='meal.php?id=%d'><b><font size='4'>%s</font></b></a><br />", $meal['id'], $meal['title']); if ($meal['description'] != '') { printf("<i>%s%s</i><br />", substr($meal['description'], 0, 150), strlen($meal['description']) > 149 ? '...' : ''); } if ($meal['ingredients'] != '') { printf("<b>Ingredients:</b> "); printf("%s<br />", implode(", ", $ing_list)); }