Welcome Guest, Not a member yet? Register   Sign In
Displaying Parent/Child lists
#5

[eluser]emuexplosion[/eluser]
This is what I've come up with. It works for what it is right now, I've just got to come up with the code to pull the department names out of the db rather than the id numbers of them. Shouldn't be too hard. Thanks for the help.

Code:
function getStaff()
    {    

            $this->db->select('*');
            $this->db->from('staff');
            $this->db->join('departments', 'departments.id = staff.department', 'left');
            $this->db->orderby('departments.display', 'asc');
            $query = $this->db->get();

            $dpt='';
            $output='';
            if ($query->num_rows() > 0) {
                foreach ($query->result() as $staff) {
                    if($dpt != $staff->department)
                    {
                        if($dpt!='')
                            $output .= '</ul>';
                        $dpt = $staff->department;
                        $output .= '<h1>'.$dpt.'</h1>';
                        $output .= '<ul>';
                    }
                    $output .= '<li><strong>' . $staff->fname . ' ' . $staff->lname . '</stong></li>';
                }
                return $output;
            } else {
                return '<p>Sorry, no results returned.</p>';
            }
    }


Messages In This Thread
Displaying Parent/Child lists - by El Forum - 06-30-2007, 02:26 PM
Displaying Parent/Child lists - by El Forum - 06-30-2007, 04:23 PM
Displaying Parent/Child lists - by El Forum - 06-30-2007, 05:25 PM
Displaying Parent/Child lists - by El Forum - 07-01-2007, 03:46 AM
Displaying Parent/Child lists - by El Forum - 07-01-2007, 09:23 AM



Theme © iAndrew 2016 - Forum software by © MyBB