Welcome Guest, Not a member yet? Register   Sign In
Sending results from a query to another query in the controller (newbie question)
#1

[eluser]Juan Velandia[/eluser]
Hello, I've already ask for help in this matter, but I couldn't hit the spot, so here I am again:

I'm sending a query directly from the controller to the view to make a list within a list like this:

placeholder 1
- section1
- section2
- section3

placeholder 2
- section4
- section5
- section

This is the controller:

Code:
function test(){
    
    $data['query1'] = $this->db->get('cms_placeholder');
    $data['query2'] = $this->db->get('cms_section_content');
    $data['result2'] = $data['query2']->result();
    $this->load->view('test', $data);

}

where cms_section_content has a column placeholder

Here's the view:

Code:
<?php foreach ($query1->result() as $row): ?>
<h1>&lt;?echo $row->name?&gt;</h1>
&lt;? $placeholder = $row->placeholder; ?&gt;
&lt;?php foreach ($query2->result() as $row): ?&gt;
<p>&lt;?echo $row->name?&gt;</p>
&lt;?php endforeach; ?&gt;
&lt;?php endforeach; ?&gt;

But I always get this: Message: Undefined variable: placeholder. I don’t want to pass variables via URL therefore I was thinking to put a query within the view to make the $placeholder available, but I’m sure there’s a more elegant solution, Thanks in advance for any idea!
#2

[eluser]Juan Velandia[/eluser]
Anyone?
#3

[eluser]fesweb[/eluser]
I don't think your code is going to do what you seem to want it to do, but maybe it's just a simplified version of what your trying to do.
Code:
// Is it as simple as needing to declare that var first?
&lt;?php $placeholder = ''; ?&gt;
&lt;?php foreach ($query1->result() as $placeholder_row): ?&gt;
<h1>&lt;?echo $placeholder_row->name?&gt;</h1>
// is your goal here to compare this placeholder with the one from the previous loop?
&lt;? $placeholder = $placeholder_row->placeholder; ?&gt;
&lt;?php foreach ($query2->result() as $section_content_row): ?&gt;
<p>&lt;?echo $section_content_row->name?&gt;</p>
&lt;?php endforeach; ?&gt;
&lt;?php endforeach; ?&gt;
#4

[eluser]Juan Velandia[/eluser]
Hello, Fesweb I'll check it, thanks a lot!!!




Theme © iAndrew 2016 - Forum software by © MyBB