Welcome Guest, Not a member yet? Register   Sign In
pass parameter to a select query from previous query
#1

[eluser]Unknown[/eluser]
I'm creating a little management tool for the browser game travian. So I select all the villages from the database and I want to display some content that's unique to each of the villages. But in order to query for those unique details I need to pass the id of the village. How should I do this?

this is my code (controller):

Code:
function members_area()
    {
        global $site_title;
        $this->load->model('membership_model');

        if($this->membership_model->get_villages())
        {
            $data['rows'] = $this->membership_model->get_villages();
            $id = 1;//this should be dynamic, but how?
            if($this->membership_model->get_tasks($id)):
                $data['tasks'] = $this->membership_model->get_tasks($id);
            endif;
        }

        $data['title'] = $site_title." | Your account";
        $data['main_content'] = 'account';
        $this->load->view('template', $data);
    }

and this is the 2 functions I'm using in the model:

Code:
function get_villages()
{
    $q = $this->db->get('villages');

    if($q->num_rows() > 0) {
        foreach ($q->result() as $row) {
            $data[] = $row;
        }
    return $data;
    }
}

function get_tasks($id)
{
    $this->db->select('name');
    $this->db->from('tasks');
    $this->db->where('villageid', $id);

    $q = $this->db->get();

    if($q->num_rows() > 0) {
        foreach ($q->result() as $task) {
            $data[] = $task;
        }
    return $data;
    }
}

and of course the view:

Code:
<?php foreach($rows as $r) : ?>
        <div class="village">
            <h3>&lt;?php echo $r->name; ?&gt;</h3>
            <ul>
                &lt;?php foreach($tasks as $task): ?&gt;
                    <li>&lt;?php echo $task->name; ?&gt;</li>
                &lt;?php endforeach; ?&gt;
            </ul>
            &lt;?php echo anchor('site/add_village/'.$r->id.'', '+ add new task'); ?&gt;
        </div>
    &lt;?php endforeach; ?&gt;


Messages In This Thread
pass parameter to a select query from previous query - by El Forum - 04-08-2010, 12:05 PM
pass parameter to a select query from previous query - by El Forum - 04-09-2010, 01:46 AM
pass parameter to a select query from previous query - by El Forum - 04-09-2010, 02:15 AM
pass parameter to a select query from previous query - by El Forum - 04-09-2010, 02:40 AM
pass parameter to a select query from previous query - by El Forum - 04-09-2010, 04:20 AM



Theme © iAndrew 2016 - Forum software by © MyBB