![]() |
Asending and Desending Field With Orderby - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Asending and Desending Field With Orderby (/showthread.php?tid=50310) |
Asending and Desending Field With Orderby - El Forum - 03-21-2012 [eluser]Unknown[/eluser] Hello All Developer If you want to simple ascending and descending field through on page use just use this below function and modify it if ( ! function_exists('orderBy')) { function orderBy($pageurl,$fieldName,$displayName,$page,$per_page,$getorder,$orderby){ if($getorder == 'ASC') { $order = "DESC"; } else{ $order = "ASC"; } if(($orderby == $fieldName)&&($getorder == 'ASC')){ $img = "<img src='".base_url()."images/orderup.png' border='0' />"; } elseif(($orderby == $fieldName)&&($getorder == 'DESC')){ $img = "<img src='".base_url()."images/orderdown.png' border='0' />"; }else{ $img = ""; } $display = "<a href='$pageurl/$page/$per_page/$fieldName/$order' class='order'>$displayName</a> $img"; return $display; } } make this funtion in system/helper/url_helper.php Pass All variable that you want like $pageurl = base_url()."index.php/managelanguage/index"; $fieldName = table field name; $displayName = On page you want to display; $page= If on your page paging is work, otherwise it is not important you can remove this. $per_page = If this funtion is on your page like how much record user want to show fron drop down. $getorder = ASC OR DESC (FIRST TIME); $orderby = Current You are using in orderby. (Optional , You can remove this.) After that You have to add in models function that is fetching all data from database like :- $orderby = $this->uri->segment(5,0)? $this->uri->segment(5,0):"id"; $order = $this->uri->segment(6,0)? $this->uri->segment(6,0):"ASC"; $this->db->order_by($orderby, $order); You Can use uri->segment as your postion of passing variable. Now call on page this funtion <?php echo orderBy(base_url()."index.php/managelanguage/index","languageName","Language Name",$page,$per_page,$order,$orderby)?> Basically You can give this facility in Admin panel and in user account section to show all order in cart management section. If You have any problem just revert a post on this I will guide you...thanks Prasannjit Prabhat |