I am trying to fix this pagination script. It seems when I click on the pagination links, [1], [2], [3], [4] or [5], it doesn't work. It just shows the first page and when clicking on the next numbers nothing happens.
The main page looks like this (pagination.php):
<?php
include_once('generate_pagination.php');
?>
<script type="text/开发者_JAVA百科javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script type="text/javascript" src="jquery_pagination.js"></script>
<div id="loading" ></div>
<div id="content" data-page="1"></div>
<ul id="pagination">
<?php generate_pagination() ?>
</ul>
<br/>
<br/>
<a href="#" class="category" id="marketing">Marketing</a>
<a href="#" class="category" id="automotive">Automotive</a>
<a href="#" class="category" id="sports">Sports</a>
Then, generate_pagination.php:
<?php
function generate_pagination($sql) {
include_once('config.php');
$per_page = 3;
//Calculating no of pages
$result = mysql_query($sql);
$count = mysql_fetch_row($result);
$pages = ceil($count[0]/$per_page);
//Pagination numbers
for($i=1; $i<=$pages; $i++)
{
echo '<li class="page_numbers" id="'.$i.'">'.$i.'</li>';
}
}
$ids = $_GET['ids'];
generate_pagination("SELECT COUNT(*) FROM explore WHERE category='$ids'");
?>
Where is the problem occurring and how do I rid of the problem?
As a matter of fact, programming science has a more powerful technique to find and eliminate errors in the code, instead of "looking in the script to see something".
This technique called "debugging".
IBM has nice introduction article in this art, Debugging techniques for PHP programmers.
To debug an Ajax application is quite hard, but it's still possible. Divide your task into smaller ones and debug them separately. Feel free to ask for more details.
One problem I see is that you're calling generate_pagination
without the $sql
parameter.
But I think we'd need to see what JavaScript code is being used in order to understand exactly what is wrong with the code. Where are the events defined for when you click on a page number?
精彩评论