views:

96

answers:

1

Hello, I am using this pagination class and was looking for a way to make the sql query more dynamic instead of having it hardcoded.

I have a 3 <li> elements that I want to be filter buttons, meaning when a user clicks on one of these elements I want It to send the id so I can use it in a sql query.

So for the $sql = "select * from explore where category='marketing'"; (as seen below). When the user clicks on the 'automotive' button it will change the category above to automotive.

Any help on this would be highly appreciated, Thanks.

This is what my main page looks like:

<script type="text/javascript"
    src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"&gt;&lt;/script&gt;
<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='marketing'";
    //Create a PS_Pagination object
    $pager = new PS_Pagination($conn, $sql, 3, 11, 'param1=valu1&param2=value2');
    //The paginate() function returns a mysql
    //result set for the current page
    $rs = $pager->paginate();
    //Loop through the result set
    while($row = mysql_fetch_assoc($rs)) {
            echo "<table width='800px'>";

                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>";

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

        echo "<li id='marketing'>";
            echo "Marketing";
        echo "</li>";

        echo "<li id='automotive'>";
            echo "Automotive";
        echo "</li>";

        echo "<li id='sports'>";
            echo "Sports";
        echo "</li>";

    echo "</ul>";
?>
+1  A: 

looks like this line

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

should be edited to carry variables to be tested before the sql query is run.... something maybe like:

$pager = new PS_Pagination($conn, $sql, 8, 3, 'param1=automotive&param2=sports');

then try this

if($_POST["param1"]=="automotive")
{
$sql = "select * from explore where category='automotive'";
}

and work around with it to see if you can get your desired results. I've never used the class before, but it looks like you'll have to play with these params to get your desired result

CheeseConQueso