Welcome Guest, Not a member yet? Register   Sign In
Getting Data for Multiple Lists
#1

[eluser]Unknown[/eluser]
Hello. I am trying to create a simple to do list app. I want a site to list the various clients I have and the To Dos assigned to each.

I am having trouble pulling the lists for every client. My setup currently only pulls the last client's data.

Controller
Code:
function index() {
        $this->load->model('client');
        $this->load->model('task');
        
        $data['client'] = $this->client->get_clients();
        
        foreach ($data['client'] as $client) {
            $id_client = $client['id_client'];
            $data['task'] = $this->task->get_tasks($id_client);
        }
        $this->load->view('cloud_view', $data);
    }

In the models, I return results as "result_array();"

Also, after pulling the data, how do I display it in the view?

View

Code:
<?php foreach ($client as $c) : ?>
    <?php echo $c['name_client']; ?>
    <?php echo $c['id_client']; ?>
    
    <ul>
        &lt;?php foreach ($task as $t) : ?&gt;
            &lt;?php if ($c['id_client'] == $t['id_client']) { ?&gt;
            <li>&lt;?php echo $t['content_task']; ?&gt;</li>
            &lt;?php } ?&gt;
        &lt;?php endforeach; ?&gt;
    </ul>
&lt;?php endforeach; ?&gt;

Any help is greatly appreciated. Thanks.
#2

[eluser]Naga Gotama Adhiwijaya[/eluser]
i try to help, modify your controller to this way:
Code:
function index() {
        $this->load->model('client');
        $this->load->model('task');
        
        $data['client'] = $this->client->get_clients();
        
        foreach ($data['client'] as $idx => $client) {
            $data['client'][$idx]['task'] = $this->task->get_tasks($client['id_client']);
        }

        $this->load->view('cloud_view', $data);
    }


and modify your view to this way:
Code:
&lt;?php foreach ($client as $c) : ?&gt;
    &lt;?php echo $c['name_client']; ?&gt;
    &lt;?php echo $c['id_client']; ?&gt;
    
    <ul>
        &lt;?php foreach ($c['task'] as $t) : ?&gt;
            <li>&lt;?php echo $t['content_task']; ?&gt;</li>
        &lt;?php endforeach; ?&gt;
    </ul>
&lt;?php endforeach; ?&gt;
#3

[eluser]Unknown[/eluser]
holy guac! you are amazing. thank you very much for your help. that solved everything!
#4

[eluser]Naga Gotama Adhiwijaya[/eluser]
you're welcome.. Smile




Theme © iAndrew 2016 - Forum software by © MyBB