hey bud. I'm a little new to codeigniter as well, but I'm very familiar with PHP, so I was able to sort of understand the common tasks quickly.
There is a way to do this. You can do this by using the controller to locate the URI segments. for example, if you wanted to sort by name, you could have the url represent this by something like:
http://sykotic-designz.org/index.php/firstdown/sort/name/asc. Then you can use uri-segments in the controller file to determine how the order links will work. (FYI: I wrote the entire URL including the name of your application as it was written in your controller file. I know that you have a router so it doesn't display the app name in the URL, but this doesn't effect the code below...)
This is not checked code. but something like this should work.
class FirstDown extends Controller {
function FirstDown()
{
parent::Controller();
}
function index()
{
$data['title'] = "First Down Statistics";
$this->db->where('id', $this->uri->segment(3));
$data['query'] = $this->db->get('firstdown');
if ($this->uri->segment(2) == 'sort' && $this->uri->segment(3) && $this->uri->segment(4)) {
switch ($this->uri->segment(3)) {
case 'name':
$this->db->orderby("lastname", $this->uri->segment(4));
break;
case 'smp':
$this->db->orderby("smp", $this->uri->segment(4));
break;
case 'att':
$this->db->orderby("att", $this->uri->segment(4));
break;
case 'pct':
$this->db->orderby("pct", $this->uri->segment(4));
break;
case 'yds':
$this->db->orderby("yds", $this->uri->segment(4));
break;
case 'ypa':
$this->db->orderby("ypa", $this->uri->segment(4));
break;
// case 'etc, etc etc etc...
}
$data['sort_column'] = $this->uri->segment(3);
$data['sort_order'] = $this->uri->segment(4);
}
$data['query'] = $this->db->get('firstdown');
$this->load->view('firstdown', $data);
}
}
now, as for the links in your view... this would raise the question "How do I make them clickable to reverse the order, if it is already sorted in a particular order?" Which means, if I clicked YPA and sorted it, then how would it know that if i clicked YPA again, that it would sort it in the reverse order? Well, one way to do it is to send the current sorted column and order with the $data array. And, in your view, while you're printing the column titles, you can have an if statement to determine which order it should be sorted by if the user clicks the link. kinda like this:
<table border="1">
<tr>
<td><a href="<?php print (($sort_column == 'name' && $sort_order == 'asc') ? ('firstdown/sort/name/desc/') : ('firstdown/sort/name/asc/'); ?>">Name</a></td>
<td><a href="<?php print (($sort_column == 'cmp' && $sort_order == 'asc') ? ('firstdown/sort/cmp/desc/') : ('firstdown/sort/cmp/asc/'); ?>">CMP</a></td>
<td><a href="<?php print (($sort_column == 'att' && $sort_order == 'asc') ? ('firstdown/sort/att/desc/') : ('firstdown/sort/att/asc/'); ?>">ATT</a></td>
<td><a href="<?php print (($sort_column == 'pct' && $sort_order == 'asc') ? ('firstdown/sort/pct/desc/') : ('firstdown/sort/pct/asc/'); ?>">PCT</a></td>
<td><a href="<?php print (($sort_column == 'yds' && $sort_order == 'asc') ? ('firstdown/sort/yds/desc/') : ('firstdown/sort/yds/asc/'); ?>">YDS</a></td>
<td><a href="<?php print (($sort_column == 'ypa' && $sort_order == 'asc') ? ('firstdown/sort/ypa/desc/') : ('firstdown/sort/ypa/asc/'); ?>">YPA</a></td>
</tr>
etc, etc, etc, etc....
<? foreach($query->result() as $row): ?>
<tr>
<td><?=$row->lastname?>, <?=$row->firstname?></td><td><?=$row->cmp?></td><td><?=$row->att?></td><td><?=$row->cmppct?>%</td>
<td><?=$row->yds?></td><td><?=$row->ypa?></td><td><?=$row->td?></td><td><?=$row->tdpct?>%</td><td><?=$row->ints?></td><td><?=$row->intpct?>%</td><td><?=$row->rating?></td>
</tr>
<? endforeach; ?>
I realize this isn't the most articulate explaination, but I hope you get the bulk of the idea. Like I said, I'm pretty new to codeigniter, but not new to frameworks... I've tried them all and I find codeigniter to be the best overall. Let me know if you have any more trouble or questions. I'd be glad to help you through this until you get it solid.