nade93 Posted July 4, 2010 Share Posted July 4, 2010 Hi all i am wanting to have a pagintation similar to www.currys.co.uk or www.asos.com basically, the results are so many per page, then sorted by relevance, price etc can anyone point me in the direction of a tutorial please? thanks Quote Link to comment https://forums.phpfreaks.com/topic/206714-pagination-using-sort-by-price-etc-from-database/ Share on other sites More sharing options...
ChemicalBliss Posted July 4, 2010 Share Posted July 4, 2010 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- Quote Link to comment https://forums.phpfreaks.com/topic/206714-pagination-using-sort-by-price-etc-from-database/#findComment-1081090 Share on other sites More sharing options...
nade93 Posted July 4, 2010 Author Share Posted July 4, 2010 thanks so much, will try this out Quote Link to comment https://forums.phpfreaks.com/topic/206714-pagination-using-sort-by-price-etc-from-database/#findComment-1081092 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.