I am working on a pagination script to limit the results of a database query returned. The problem is that when the next page link number is pressed, the user is just returned to the original screen with no results displaying. Any help welcome.
Here is the PHP script. Its long, wasn't sure to cut bits or just leave as is.
<?php
session_start();
$con = mysqli_connect('localhost','root','','python');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
?>
<html>
<head>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="http://ift.tt/1FHelXo">
<!-- Optional theme -->
<link rel="stylesheet" href="http://ift.tt/1GSvD1Z">
<script src="http://ift.tt/1qRgvOJ"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="http://ift.tt/19wK3Lg"></script>
<!-- Include Modernizr in the head, before any other Javascript -->
<script src="includes/js/modernizr-2.6.2.min.js"></script>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link href='http://ift.tt/1mbzEpL' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="bootstrap.css">
<link rel="stylesheet" href="stylez.css">
<script type="text/javaSript" src = "../jquery.js"></script>
<script>
function ajaxFunction(){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
}catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data
// sent from the server and will update
// div section in the same page.
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('results_box');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
// Now get the value from user and pass it to
// server script.
var gen = document.getElementById('gen').value;
var datepicker = document.getElementById('datepicker').value;
var tab = document.getElementById('tab').value;
//var datepicker = document.getElementById('datepicker').value;
var queryString = "?gen=" + gen ;
queryString += "&datepicker=" + datepicker +"&tab=" + tab;
ajaxRequest.open("GET", "main.php" +
queryString, true);
ajaxRequest.send(null);
}
</script>
<script>
//-->
</script>
<script>
$(function() {
$('#datepicker').datepicker({ dateFormat: 'yy-mm-dd' }).val();
});
</script>
<body style="background-color:black">
<nav class="navbar">
<div id="custom-bootstrap-menu" class="navbar navbar-static-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header"><a><img src="logo1.png" style="width:140px; height:50px" class="navbar-brand" href="index.html"></a>
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav navbar-right">
<li>
<a href="/">london</a>
</li>
<li>
<a href="/products">YORKSHIRE</a>
</li>
<li>
<a href="/about-us">MIDLANDS</a>
</li>
<li>
<a href="/contact">EAST ANGLIA</a>
</li>
<li>
<a href="/contact">NEWCASTLE</a>
</li>
<li>
<a href="/contact">SOUTH WEST</a>
</li>
</ul>
</div>
</div>
</div>
</nav>
<!-- Full Width Image Header with Logo -->
<!-- Image backgrounds are set within the full-width-pics.css file. -->
<header class="image-bg-fluid-height">
<img class="img-responsive img-center" src="londonb.jpg" alt="">
<img class="centered" src="lettering.png" style="height:200px; width:60%; margin-top:-300px;">
</header>
<div class="container-fluid" style="background-color:#68748D;">
<br>
<div class="row">
<div class="col-md-3">
<h2><p>Search Events</h2>
</div>
<div class="col-md-2">
<ul class = "nav">
<li ><h4>Location:<br></h4>
<select id='tab' style="background-color:white">
<option value="London" "Manchester">Choose Location</option>
<option value="London">London</option>
<option value="Manchester">Manchester</option>
</select>
</li><br>
</ul>
</div>
<div class="col-md-2">
<ul class = "nav">
<li><h4>Genre:<br><p></h4>
<select id='gen' style="background-color:white;">
<option value ="">Select</option>
<option value="Dance">Dance</option>
<option value="Drum n Bass">Drum n Bass</option>
<option value="Indie">Indie</option>
<option value="Classical">Classical</option>
<option value="Opera">Opera</option>
<option value="Blues">Blues</option>
<option value="Rock">Rock</option>
<option value="Punk">Punk</option>
<option value="Metal">Metal</option>
<option value="Indie">Festivals</option>
<option value="Folk">Folk</option>
<option value="Acoustic">Acoustic</option>
<option value="Pop">Pop</option>
<option value="Soul">Soul</option>
<option value="Country">Country</option>
<option value="Latin">Latin</option>
<option value="Jazz">Jazz</option>
<option value="Punk">Punk</option>
</select>
</li><br>
</ul>
</div>
<div class="col-md-2">
<ul class = "nav">
<li><h4>Choose Date:<br></h4>
<input type = "text" id = "datepicker" size="10" style="background-color:white"><br><p>
</li>
</ul>
</div>
<div class="col-md-2">
<ul class = "nav">
<li><h4>Submit</h4>
<input type='button' style="background-color:white""color:black" width="80%" class="btn btn-group-sm" onclick='ajaxFunction()' value='Search 4 Live'/><br><p>
</li>
</ul>
</div>
<br>
</div>
</div>
<br>
<?php
mysqli_select_db($con,"ajax");
if (isset($_GET['gen'])){
$gen = '%'.$_GET['gen'].'%';
}
if (isset($_GET['tab'])){
$tab = $_GET['tab'];
}
if (isset($_GET['datepicker'])){
$datepicker = $_GET['datepicker'];
}
$per_page = 6;
if (isset($_GET['tab'])){
$pages_query = mysqli_query($con, "SELECT * FROM $tab WHERE genre LIKE '$gen' AND dateForm = '$datepicker'");
if(!$pages_query){
printf("Error: %s\n", mysqli_error($con));
exit();
}
$row = mysqli_num_rows($pages_query);
$pages = ceil($row) / $per_page;
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$start = ($page - 1) * $per_page;
echo $row;
$sql="SELECT * FROM $tab WHERE genre LIKE ? AND dateForm = ? LIMIT ?, ?";
// Prepare, bind, and execute
$stmt = mysqli_prepare($con,$sql);
mysqli_stmt_bind_param($stmt, 'ssss', $gen, $datepicker, $start, $per_page);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$row = mysqli_fetch_row($result);
//$pages_query = mysqli_num_rows($result);
//echo ("-----"),ceil($pages);
echo "<table class='table table-hover'><thead>
<tr>
<th><h3>Artist</th>
<th><h3>Location</th>
<th><h3>Date</th>
<th><h3>Genre</th>
<th><h3>Preview</th>
</tr></thead>";
?>
<?php
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['artist'] . "</td>";
echo "<td> <b>Venue: </b>" . $row['venue'] . "<p><b>Location: </b>" . $row['location'] . "</td>";
echo "<td>" . $row['datez'] . "</td>";
echo "<td>" . $row['genre'] . "</td>";
echo "<td>" . '<iframe width="100%" height="100" scrolling="no" frameborder="no" src="http://ift.tt/1bFBFZN' . $row['link'] . '&color=000000&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false"></iframe>' . "</td>";
echo "</tr>";
}
echo "</table>";
if ($pages >= 1){
for($x=1; $x<=$pages;$x++){
echo '<a href="?page='.$x.'">'.$x.'</a>';
}
}
}
?>
<div id='results_box'></div>
<?php
mysqli_close($con);
?>
</body>
</html>
Aucun commentaire:
Enregistrer un commentaire