I am still trying to update my SQL query more dynamically, but have been at a loss since both PHP and jquery appeared.
I have one main page (pagination.php) that looks like this:
<?php
function generate_pagination($sql) {
include_once('config.php');
$per_page = 3;
$result = mysql_query($sql);
$count = mysql_fetch_row($result);
$pages = ceil($count[0]/$per_page);
for($i=1; $i<=$pages; $i++)
{
echo '<li class="page_numbers" id="'.$i.'">'.$i.'</li>';
}
}
?>
<script type="text/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("SELECT COUNT(*) FROM explore WHERE category='marketing'"); ?>
<a href="#" class="category" id="marketing">Marketing</a>
<a href="#" class="category" id="automotive">Automotive</a>
<a href="#" class="category" id="sports">Sports</a>
As you can see, the top of the script calculates the number of pages to paginate and then displays the numbers depending on the number of results in the database for this query:
<?php generate_pagination("SELECT COUNT(*) FROM explore WHERE category='marketing'");
It was, if I had difficulties, I want to make a dynamic part of a part of the above request. Thus, when the user clicks on any of the three links, I want the link identifier to be placed in part of the query part using jquery.
Here is my jquery code:
$("#pagination a").click(function () {
Display_Load();
var this_id = $(this).attr('id');
var pageNum = $('#content').attr('data-page');
$("#content").load("filter_marketing.php?page=" + pageNum +'&id='+this_id, Hide_Load());
});
I hope this made sense, and if someone can help me with this, it will be great.