Welcome Guest, Not a member yet? Register   Sign In
SOLVED: How can i include a foreach loop in the template parser array?
#2

[eluser]TheFuzzy0ne[/eluser]
Selected Options should be an array should it not? I don't understand the loop. You're overwriting the selected_options variable with each iteration of the loop. If I understand the problem correctly, to get a loop in your view you'd need to do something like this:

Code:
{selected_options}
    {option_id}
    {option_title}
{/selected_options}
(You need to change the names to match the names of the database fields you want to display).


By using $this->input->post(), you can save yourself a line of code. I also feel you need a bit more checking going on in your foreach loop. I've rewritten your code below, with my proposed changes.
Code:
$selected_options = array();

// Checkbox loop
if ($option = $this->input->post('option'))
{
    foreach ($option as $option_id)
    {
        $res = $this->db->get_where('opties', array('id', $option_id));

        if ($res->num_rows())
        {
            $selected_options[] = $res->row_array();
        }
    }
};

// Set data
$data['selected_options'] = $selected_options);

// Parse Template
$this->parser->parse('options_view', $data);

I haven't tested it, but I think it does what you want it to.


Messages In This Thread
SOLVED: How can i include a foreach loop in the template parser array? - by El Forum - 05-06-2009, 08:01 AM



Theme © iAndrew 2016 - Forum software by © MyBB