Welcome Guest, Not a member yet? Register   Sign In
Sorting Database columns using codeigniter
#1

[eluser]jason97673[/eluser]
So I am new to useing codeigniter and there isnt as much documentation on this as there is just plain PHP without a framework.

Well I am making a simple site (for now) that has many fields and is grabbing the records from a database. I want to be able to click on the column headers and sort them. I want to beable to have them be clicked and have it sorted DESC or ASC.

Using regular PHP I can do this but not using the codeigniter framework. Ill show you the site. http://sykotic-designz.org

When you visit the site it is a simple table with many fields and for now only 2 records. I want to beable to click name and have it sort from A-Z(then if possible have it sort the opposite direction if clicked again). Or if you click CMP, ATT, CMP % etc, have those sorted from higher to lower(then the opposite direction if possible when clicked again).

My code right now in the view is
Code:
<table border="1">
   <tr>
       <td>Name</td><td>CMP</td><td>ATT</td><td>PCT</td><td>YDS</td><td>YPA</td><td>TDs</td><td>TD%</td><td>INTs</td><td>INT%</td><td>RAT</td>
    </tr>
&lt;? foreach($query->result() as $row): ?&gt;

   <tr>
      <td>&lt;?=$row->lastname?&gt;, &lt;?=$row->firstname?&gt;</td><td>&lt;?=$row->cmp?&gt;</td><td>&lt;?=$row->att?&gt;</td><td>&lt;?=$row->cmppct?&gt;%</td>
        <td>&lt;?=$row->yds?&gt;</td><td>&lt;?=$row->ypa?&gt;</td><td>&lt;?=$row->td?&gt;</td><td>&lt;?=$row->tdpct?&gt;%</td><td>&lt;?=$row->ints?&gt;</td><td>&lt;?=$row->intpct?&gt;%</td><td>&lt;?=$row->rating?&gt;</td>
    </tr>

&lt;? endforeach; ?&gt;

The code in the controller is
Code:
class FirstDown extends Controller {
  
   function FirstDown()
   {
      parent::Controller();
   }
  
   function index()
   {
      $data['title'] = "First Down Statistics";
      $this->db->orderby("lastname", "asc");
      $data['query'] = $this->db->get('firstdown');
      $this->load->view('firstdown', $data);
   }
}

Thanks for any help.


Messages In This Thread
Sorting Database columns using codeigniter - by El Forum - 04-26-2009, 12:05 PM
Sorting Database columns using codeigniter - by El Forum - 04-26-2009, 12:12 PM
Sorting Database columns using codeigniter - by El Forum - 04-26-2009, 12:24 PM
Sorting Database columns using codeigniter - by El Forum - 04-26-2009, 12:26 PM
Sorting Database columns using codeigniter - by El Forum - 04-26-2009, 12:32 PM
Sorting Database columns using codeigniter - by El Forum - 04-26-2009, 12:35 PM
Sorting Database columns using codeigniter - by El Forum - 04-26-2009, 08:39 PM
Sorting Database columns using codeigniter - by El Forum - 04-26-2009, 09:49 PM
Sorting Database columns using codeigniter - by El Forum - 04-30-2009, 06:29 PM
Sorting Database columns using codeigniter - by El Forum - 04-30-2009, 07:43 PM



Theme © iAndrew 2016 - Forum software by © MyBB