views:

95

answers:

2

Hello, I am wondering if there is a possibility.

I have a pagination script that grabs the content from a mysql database with php and using jquery to handle it all.

I want to add a filter to the pagination which will get rid of some content based on the users selection.

When the filter is set I would like the pagination numbers to update to compensate for the items that have been removed.

My biggest concern is that I'm getting the amount of pages to display directly from the database which would make it impossible to update the pagination numbers when filtered:

<?php
include('config.php');
$per_page = 3;

//Calculating no of pages
$sql = "select * from explore";
$result = mysql_query($sql);
$count = mysql_num_rows($result);
$pages = ceil($count/$per_page)
?>

Does anyone know if it is still possible to update these numbers when filtered.

Im mostly using this tutorial in case your wondering: Here

+1  A: 

The solution is to do the filtration sever side. IE when you apply a filter you send the data to the server and the sql is updated to include/exclude whatever your filter says.

Byron Whitlock
I'm not sure I understand completely. I update the database? Is there an example of this? Thanks.
Dr.Flow
+1  A: 

Just to expand on what Byron said, here is how you do this (based on the code from your link):

Right now in the pagination.php there is a line that looks like this

  $sql = "select * from messages";

and in pageination_data.php like this:

  $sql = "select * from messages order by msg_id limit $start,$per_page";

Lets say you want a filter that only shows today's messages.

then you would need the following two lines:

  $sql = "select * from messages where messages.date = curdate() ";
  $sql = "select * from messages where messages.date = curdate() order by msg_id limit $start,$per_page";

of course I expect you will generate the sql statements dynamically in some way. What this allows is the sql server to do the filtering, all the application code stays as you have it.

Note: Remember if you are making dynamic sql to not leave yourself open to sql injection attacks. There are a number of other questions that address sql injection.

Hogan