Welcome Guest, Not a member yet? Register   Sign In
Help with array refencing database table.
#3

[eluser]OwanH[/eluser]
Hey,

I would suggest normalizing your database further so you can have better table relationships. Here are what the normalized tables would look like (I'm arbitrarily assuming the names in your works table are clients):

Client Table:
+++++++++
ID name
—————————
1 Nike
2 Dell
3 IBM
+++++++++

Task Table:
++++++++++++++
ID name
—————————————
1 Design
2 Development
3 Research
4 Concepting
++++++++++++++

Works Table:
+++++++++++++++++++++++++++++++++++++
ID client_id task_id active
—————————————————————————————————————
1 1 1 1
2 1 3 1
3 1 3 1
4 2 3 1
5 2 1 1
6 2 5 1
7 3 4 1
8 3 2 1
+++++++++++++++++++++++++++++++++++++

Your model will then become

Code:
class MOurWork extends My_Model {

    function MOurWork() {
        parent::My_Model();
    }
    
    function getAllWorks(){
        $data = array();
        $query = $this->db->query('SELECT works.id, works.client_id, client.name, works.task_id, task.name FROM works LEFT JOIN client ON (works.client_id=client.id) LEFT JOIN task ON (works.task_id=task.id) WHERE works.active="1"');
        if ($query->num_rows() > 0){
            foreach ($query->result_array() as $row){
                $data[] = $row;    
            }
        }
        $query->free_result();
        return $data;
    }
}


Hope this helps.


Messages In This Thread
Help with array refencing database table. - by El Forum - 01-09-2009, 12:44 PM
Help with array refencing database table. - by El Forum - 01-09-2009, 03:25 PM
Help with array refencing database table. - by El Forum - 01-09-2009, 05:42 PM



Theme © iAndrew 2016 - Forum software by © MyBB