I am trying to add a results filter to my website. When I attempt to concatenate the query, the screen is blank upon form submission. No errors or anything. No content whatsoever.
Code:
$qry = "SELECT * FROM dining_listings WHERE dining_type = ?";
$conditions[] = array();
if(isset($_POST['west'])) {
$conditions[] = "dining_tags LIKE '%west%'";
}
if(isset($_POST['turkeycreek'])){
$conditions[] = "dining_tags LIKE '%turkey-creek%'";
}
$sql = $query;
if(count($conditions) > 0){
$sql .= implode('AND' . $conditions);
}
$getRest = $conn->prepare($sql);
$getRest->bind_param("s", $dt);
$getRest->execute();
$getRestResult = $getRest->get_result();
I have tried this too:
Code:
$qry = "SELECT * FROM dining_listings WHERE dining_type = ?";
if(isset($_POST['west'])) {
$qry .= "AND dining_tags LIKE '%west%'";
}
if(isset($_POST['turkeycreek'])){
$qry .= "AND dining_tags LIKE '%turkey-creek%'";
}
$getRest = $conn->prepare($qry);
$getRest->bind_param("s", $dt);
$getRest->execute();
$getRestResult = $getRest->get_result();
Here is the entire code :eek: surprise!
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<?php require("includes/head.php"); ?>
<title>Starter Template for Bootstrap</title>
<style>
body{
background:linear-gradient(to right, #303947, #3f5c87, #303947);
background-repeat:no repeat;
}
.onhov:hover{
transform:scale(1.05,1.05);
}
</style>
<style type="text/css">
#map { width: 100%; height: 400px; border: 0px; padding: 0px; }
</style>
<script src="http://maps.google.com/maps/api/js?key=AIzaSyC44-T0YBhP1JLkuhQxWHoHq0lS0bZsdDk&sensor=false" type="text/javascript"></script>
<script type="text/javascript">
var icon = new google.maps.MarkerImage("http://maps.google.com/mapfiles/ms/micons/blue.png",
new google.maps.Size(32, 32), new google.maps.Point(0, 0),
new google.maps.Point(16, 32));
var center = null;
var map = null;
var currentPopup;
var bounds = new google.maps.LatLngBounds();
function addMarker(lat, lng, info) {
var pt = new google.maps.LatLng(lat, lng);
bounds.extend(pt);
var marker = new google.maps.Marker({
position: pt,
icon: icon,
map: map
});
var popup = new google.maps.InfoWindow({
content: info,
maxWidth: 300
});
google.maps.event.addListener(marker, "click", function() {
if (currentPopup != null) {
currentPopup.close();
currentPopup = null;
}
popup.open(map, marker);
currentPopup = popup;
});
google.maps.event.addListener(popup, "closeclick", function() {
map.panTo(center);
currentPopup = null;
});
}
function initMap() {
map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(0, 0),
zoom: 5,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
},
navigationControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.ZOOM_PAN
}
});
<?php
if(isset($_GET['type'])) {
$dt = strip_tags(trim($_GET['type']));
$qry = "SELECT * FROM dining_listings WHERE dining_type = ?";
$conditions[] = array();
if(isset($_POST['west'])) {
$conditions[] = "dining_tags LIKE '%west%'";
}
if(isset($_POST['turkeycreek'])){
$conditions[] = "dining_tags LIKE '%turkey-creek%'";
}
$sql = $query;
if(count($conditions) > 0){
$sql .= implode('AND' . $conditions);
}
$getRest = $conn->prepare($sql);
$getRest->bind_param("s", $dt);
$getRest->execute();
$getRestResult = $getRest->get_result();
if($getRestResult->num_rows != 0) {
while($row = $getRestResult->fetch_assoc()) {
$dinName = $row['dining_name'];
$dinLat = $row['dining_lat'];
$dinLong = $row['dining_long'];
echo("addMarker({$dinLat}, {$dinLong}, '<b>hi</b><br />a place');n");
}
}else{
echo("Error");
//redir("diningbytype.php");
//exit();
}
}else{
echo("Error");
//redir("diningbytype.php");
//exit();
}
?>
center = bounds.getCenter();
map.fitBounds(bounds);
}
</script>
<?php
if(isset($_GET['error'])) {
$error = $_GET['error'];
switch($error) {
case 300;
?>
<script>$(document).ready(function () {
$('#signInMod').modal('show');
});</script>
<div class="modal" id="signInMod" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Sign In</h4>
</div>
<div class="modal-body">
<form method="POST" action="includes/loginprocess.php" autocomplete="off">
<div class="form-group">
<label>Username</label>
<input type="text" maxlength="15" name="uname" class="form-control" placeholder=""/>
</div>
<div class="form-group">
<label>Password</label>
<input type="password" maxlength="15" name="passw" class="form-control" placeholder=""/>
</div>
</div>
<div class="modal-footer">
<button type="button" onclick="redirectback();" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" name="signinbut" class="btn btn-primary">Sign In</button>
</form>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script>
function redirectback() {
var location = "dincat.php?type=" + <?php echo(json_encode($dt)); ?>;
window.location.replace(location);
}
</script>
<?php
break;
case 301;
?>
<script>$(document).ready(function () {
$('#alreadySaved').modal('show');
});</script>
<div class="modal" id="alreadySaved" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Notice</h4>
</div>
<div class="modal-body">
<span class="fa fa-exclamation-triangle" style="font-size:40px;"></span>
<span style="font-size:16px;">You have already saved this location.</span>
</div>
<div class="modal-footer">
<button type="button" onclick="redirectback();" class="btn btn-primary" data-dismiss="modal">Ok</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script>
function redirectback() {
var location = "dincat.php?type=" + <?php echo(json_encode($dt)); ?>;
window.location.replace(location);
}
</script>
<?php
break;
}
}
?>
</head>
<body style="padding-top:60px" onload="initMap()">
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<img class="brand-image" src="ktowntrans.png" width="125px;"/>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav" style="margin-left:20px;">
<li class="active"><a href="#">Dining</a></li>
<li><a href="#about">Shopping</a></li>
<li><a href="#contact">Living</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<div class="col-md-2">
<?php include("includes/quicklinks.php"); ?>
<div class="well" style="border-radius:0 !important; background-color:rgba(0,0,0,0.2); border:0 !important; color:white;">
<form method="POST" action="dincat.php?type=<?php echo($dt); ?>">
<div style="font-size:20px;">Filter Results</div><br/>
<div class="form-group">
<label>By Region</label><br/>
<input type="checkbox" name="west" value="west"/> West Knox <br/>
<input type="checkbox" name="downtown" value="downtown"/> Downtown <br/>
<input type="checkbox" name="north" value="north"/> North Knox <br/>
<input type="checkbox" name="south" value="south"/> South Knox<br/>
</div>
<div class="form-group">
<label>By Community</label><br/>
<input type="checkbox" name="farragut" value="farragut"/> Farragut/Concord<br/>
<input type="checkbox" name="powell" value="powell"/> Powell<br/>
<input type="checkbox" name="strawberry-plains" value="strawberry-plains"/> Strawberry Plains<br/>
<input type="checkbox" name="bearden" value="bearden"/> Bearden<br/>
<input type="checkbox" name="west-town" value="south"/> West-Town<br/>
</div>
<div class="form-group">
<label>By Shopping District</label><br/>
<input type="checkbox" name="turkeycreek" value="turkey-creek"/> Turkey Creek<br/>
<input type="checkbox" value=""/> West Town Mall<br/>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Filter</button>
</div>
</form>
</div>
</div>
<div class="col-md-8">
<div class="row" style="border-radius:0 !important; background-color:rgba(0,0,0,0.2); border:0 !important; color:white; padding:10px;">
<span><a href="diningbytype.php">Dining by type</a> > <?php echo(ucwords($dt)); ?></span>
<h1><?php echo(ucwords($dt)); ?></h1>
<div id="map"></div>
</div>
<div class="row">
<?php
$qry = "SELECT * FROM dining_listings WHERE dining_type = ?";
$getRest = $conn->prepare($qry);
$getRest->bind_param("s", $dt);
$getRest->execute();
$getRestResult = $getRest->get_result();
if($getRestResult->num_rows != 0) {
while($row = $getRestResult->fetch_assoc()) {
$dinName = $row['dining_name'];
$dinStreet = $row['dining_street'];
$dinCity = $row['dining_city'];
$dinState = $row['dining_state'];
$dinZip = $row['dining_zip'];
$dinPhone = $row['dining_phone'];
$dinType = $row['dining_type'];
$dinId = $row['id'];
?>
<div class="col-md-6">
<div class="thumbnail onhov" style="border-radius:0 !important; background-color:rgba(0,0,0,0.2); border:0 !important; color:white; padding:10px; margin-top:10px;">
<div class="row">
<div class="col-md-4" style="padding-top:5px; padding-bottom:10px;">
<img src="http://www.placehold.it/100x100" width="100%"/>
</div>
<div class="col-md-5">
<span style="font-size:22px;"><a href="restaurantinfo.php?loc=<?php echo($dinId); ?>"><?php echo(ucwords($dinName)); ?></a></span><br/>
<p>
<?php echo($dinStreet); ?><br/>
<?php echo($dinCity); ?>, <?php echo($dinState . " " . $dinZip); ?> </br>
<?php echo($dinPhone); ?>
</p>
</div>
<div class="col-md-3" style="padding-top:5px;">
<form method="POST" action="saveit.php">
<input type="hidden" value="<?php echo($dinId); ?>" name="dinid"/>
<input type="hidden" value="dincat.php?type=<?php echo($dinType); ?>" name="redirloc"/>
<button type="submit" name="saveitsubbut" class="btn" style="background-color:#ea15bc;"><span class="fa fa-heart"></span> Save</button>
</form>
</div>
</div>
</div>
</div>
<?php
}
}else{
echo("No results exist");
}
?>
</div>
</div>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script>window.jQuery || document.write('<script src="../../assets/js/vendor/jquery.min.js"></script>')</script>
<script src="../../dist/js/bootstrap.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="../../assets/js/ie10-viewport-bug-workaround.js"></script>
</body>
</html>
CodingForums...
ما را در سایت CodingForums دنبال می کنید
برچسب : نویسنده : codingforums بازدید : 202 تاريخ : شنبه 28 مرداد 1396 ساعت: 6:05