Welcome Guest, Not a member yet? Register   Sign In
Query database and insert result in an existing array
#1

[eluser]keugant[/eluser]
Hello everyone,

I'm currently working on a community site built with CodeIgniter and I keep bumping into an error while trying to insert some data in an existing array. I'm new to the MVC pattern and to the framework itself so please excuse any obvious error.

Here is the problem and source code:

I query the database to get a list of groups (in the model):
Code:
public function view_groups() {
                $sql = "SELECT
                                `id`, `name`, `description`
                        FROM
                                `groups`";
                $query = $this->db->query($sql);
                return $query->result();
}

Then, while the results are passed to the controller, I send them back to another function to check if the current user have joined the group:
Controller:
Code:
public function groups() {
                        $this->load->model('groups_model');
                        $results = $this->groups_model->view_groups();
                        foreach($results as $row) {
                                $status = $this->groups_model->is_joined($row->id);
                                if($status == TRUE) {
                                        $row->status => 'true';
                                }
                                else {
                                        $row->status => 'false';
                                }
                        }
                

                $this->load->view('includes/template', array(
                        'groups' => $results,
                        'main_content' => 'groups'
                ));
        }

Model:
Code:
public function is_joined($group_id) {
                $sql = "SELECT * FROM `interface_groups` WHERE `user_id` = ".$this->session->userdata('id')."AND `group_id` = ".$group_id;
                
                $query = $this->db->query($sql);
                if($query->num_rows() > 0) {
                        return true;
                }      
                else {
                        return false;
                }      
        }

The purpose is to get the existing groups (that can be created by users), I check if the current user is part of them or not (detail stored in the interface_group table). But, all I get is a blank page..

Could you please help.

Thank you


Messages In This Thread
Query database and insert result in an existing array - by El Forum - 03-08-2013, 01:34 PM
Query database and insert result in an existing array - by El Forum - 03-08-2013, 02:16 PM
Query database and insert result in an existing array - by El Forum - 03-08-2013, 04:12 PM
Query database and insert result in an existing array - by El Forum - 03-10-2013, 10:16 AM



Theme © iAndrew 2016 - Forum software by © MyBB