$first_condition = false; if (isset($_POST['unrated_adventures'])) { if ($min_rating == 0) { $search_query .= "rating <= {$max_rating} "; } else { $search_query .= "rating <= {$max_rating} ))"; } } else { $search_query .= "rating <= {$max_rating} "; } } } if (!$first_condition) { $result = $mySQL->query($search_query); } if (!$first_condition && $result->num_rows > 0) { echo "<div class='alert alert-info'>Found {$result->num_rows} results.</div>"; while ($row = $result->fetch_assoc()) { echo "\n\t<div class='panel panel-default' style='margin-top: 10px;'>\n\t\t<div class='panel-heading' style='background-color: orange;'>\n\t\t\t<a href='adventure.php?id={$row['adventure_id']}'>" . $row['title']; if ($row['rating'] != 0) { echo " (Rating: {$row['rating']})"; } else { echo " (Not rated yet)"; } echo "</a>\n\t\t\t<span style='float:right;' class='glyphicon glyphicon-user'><a href='profile.php?user={$row['user_id']}'>{$user->getUsernameFromID($row['user_id'])}</a></span>\n\t\t</div>\n\t\t<div class='panel-body'>\n\t\t\t<span style='float:right;' class='glyphicon glyphicon-globe'>" . $a->getCountryNameById($row['country_id']) . "</span><hr />\n\t\t\t<img src='" . getPictureFilename($row['main_picture_id'], $mysql) . "' height='300px' width='450px'>\n\t\t\t<h4>Description</h4>\n\t\t\t<div class='well well-sm'>\n\t\t\t\t<span>{$adv->createShortDescription($row['description'])}...</span>\n\t\t\t</div>\n\t\t</div>\n\t</div>"; } } else { echo "<div class='alert alert-warning'>No results were found. Please update parameteres and try again. </div>"; } } require_once "site_footer.php";
function getAdventure($id, $mysql) { $stmt = $mysql->prepare("SELECT * FROM adventure WHERE adventure_id=?"); $stmt->bind_param("i", $id); $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows == 1) { $row = $result->fetch_assoc(); $adventure['adventure_id'] = $row['adventure_id']; $adventure['title'] = $row['title']; $adventure['description'] = $row['description']; $adventure['country'] = getCountryName($row['country_id'], $mysql); $adventure['main_picture'] = getPictureFilename($row['main_picture_id'], $mysql); $adventure['rating'] = $row['rating']; $adventure['user_id'] = $row['user_id']; $result = $mysql->query("SELECT username FROM users WHERE user_id={$row['user_id']}"); $user_row = $result->fetch_assoc(); $adventure['username'] = $user_row['username']; $result = $mysql->query("SELECT picture_id,name FROM picture where adventure_id={$id}"); $i = 0; while ($picture = $result->fetch_assoc()) { if ($picture['picture_id'] != $row['main_picture_id']) { $adventure['picture'][$i] = "./uploads/" . $picture['name']; } $i++; } $result = $mysql->query("SELECT value FROM tags where adventure_id={$id}"); $i = 0; while ($tag = $result->fetch_assoc()) { $adventure['tag'][$i] = $tag["value"]; $i++; } $result = $mysql->query("SELECT * FROM comments WHERE adventure_id = {$id} ORDER BY comment_id ASC"); $comments = array(); while ($comment = $result->fetch_assoc()) { array_push($comments, $comment); } $adventure['comments'] = $comments; $title = $adventure['title']; return $adventure; } else { return null; } }