Converting PHP pagination to jQuery?

Posted by ClarkSKent on Stack Overflow See other posts from Stack Overflow or by ClarkSKent
Published on 2010-04-07T20:51:52Z Indexed on 2010/04/07 23:43 UTC
Read the original article Hit count: 209

Filed under:
|
|

Hey, I have been trying to get this pagination class that I am using to be more ajaxy - meaning when I click on the page number like page [2] the data loads, but I want to load in the data without going to a different page (HTTP request in the background, with no page reloads).

Being new to both php and jquery, I am a little unsure on how to achieve this result, especially while using a php class.

This is what the main page looks like by the way:

<?php
$categoryId=$_GET['category'];
echo $categoryId;
?>

<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_page.js"></script>

<?php
    //Include the PS_Pagination class
    include('ps_pagination.php');
    //Connect to mysql db
    $conn = mysql_connect('localhost', 'root', 'root');
    mysql_select_db('ajax_demo',$conn);
    $sql = "select * from explore where category='$categoryId'";
    //Create a PS_Pagination object
    $pager = new PS_Pagination($conn, $sql, 3, 11, 'param1=value1&param2=value2');
    //The paginate() function returns a mysql
    //result set for the current page
    $rs = $pager->paginate();
    //Loop through the result set

echo "<table width='800px'>";

    while($row = mysql_fetch_assoc($rs)) {            

                echo "<tr>";
                    echo"<td>";
                        echo $row['id'];
                    echo"</td>";

                    echo"<td>";
                        echo $row['site_description'];
                    echo"</td>";

                    echo"<td>";
                        echo $row['site_price'];
                    echo"</td>";
                echo "</tr>";

    }
echo "</table>";

        echo "<ul id='pagination'>";

            echo "<li>";
            //Display the navigation
            echo $pager->renderFullNav();
            echo "</li>";

        echo "</ul>";

?>

<div id="loading" ></div>
<div id="content" ></div>

Would I need to do something with this part of the class?, as seen above:

$pager = new PS_Pagination($conn, $sql, 3, 11, 'param1=value1&param2=value2');

Or this?:

echo $pager->renderFullNav();

I don't no much about jquery,but i guess I would start it like:

$("#pagination li").click(function() {

Then load something maybe...

I don't no. Any help on this would be great. Thanks.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about php