views:

33

answers:

2

Wondering how I can do this with CodeIgniter? alt text

Any help is greatly appreciated!

Thanks.

A: 

There's no built in function to do this. You'll have to loop through an sql query to do this...

Select * from table order by field asc

foreach ( $result as $thing ) {

    if ( $thing['name'][0] != $first_letter) {
        echo '<h2>' . $thing['name'][0] . '</h2>';
        $first_letter = $thing['name'][0];
    }
    echo $result['thing'];

}

this is just a rough example...never echo html like that.

Galen
A: 
  1. //in model public function alphaDirectory(){ // Query for data $sql = "SELECT SUBSTRING(column_name,1,1) AS letter, column_name,column_link FROM table ORDER BY column_name"; $query = $this->db->query($sql); $columnByName="";

foreach ($query->result() as $row) { $columnByName[$row->letter][] = array($row->column_name,$row->column_link); } return $columnByName; }

  1. //in controller call the model and pass the return array to view

  2. in view

      $V){ echo "
    • ".strtoupper($k)."
      • "; foreach($v as $links){ echo "
      • ".$links[0]."
      • "; } echo '
      ' } ?>

  3. use css to decorate to get exact match as you are looking

JapanPro