Jump to content

Recommended Posts

This is a good tutorial, even if you don't know about classes, by the end of this one you'll get a good idea at least;

http://www.talkphp.com/advanced-php-programming/1660-advance-pagination-class.html

 

What you would do is add a "Filter" method, and "Sort By" Method. These methods would be called before the setData() method call.

This would set the relevant "Member Properties" (Class Variables) so that setData can implement them in the SQL string.

 

eg: Modified setData Function;

            function setData($table){
                    
                  $this->table = $table;
                  
                  // For multiple field sorts/orders.. (They will be sorted right to left, most dominant sort field will be the first in the array.)
                  if(is_array($this->order) && count($this->order) != 0){
                                    $orders = array();
                                    
                                    
                                    // Loop each order, $order = array([0]=>array([0]=>'fieldname',[1]=>'asc/desc'),[1]=>array([0]=>'fieldname2',[1]=>'asc/desc'));
                                    foreach($this->order as $item){ // $item would be array([0]=>'fieldname',[1]=>'asc/desc')
                                                      $orders[] = "`".$item[0]."` ".$item[1];
                                    }
                                    $order = implode(", ", $orders);
                  }
                  
                  $this->sql = "SELECT * FROM ".$this->table." ".$sort." ".$order." LIMIT ".$this->limits.",".$this->max_r."";
                  $this->sql = mysql_query($this->sql) or die(mysql_error());
                  $this->total = "SELECT * FROM ".$this->table."";
                  $this->totalres =  mysql_query($this->total) or die(mysql_error());
                  $this->count_all = mysql_num_rows($this->totalres);
                  $this->totalpages = ceil($this->count_all / $this->max_r);
            } 

 

You will have to make the actually filter function that will make the order array (or add to it so you can call the method numerous times).

 

I'll leave that to you, but do this in order:

1. Read through that tutorial, implement that exact code to your current project.

2. Come and look at this code, and write it, dont copy/paste - fi you write it you may understand it easier.

3. Try to create your own filter method, Personally i would call it addFilter() but that's totally up to you. If you et stuck give don't hesitate to ask.

 

-cb-

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.