Welcome Guest, Not a member yet? Register   Sign In
Passing multiple query results to view?
#1

[eluser]rich.a.coy[/eluser]
Hello,

I have a dashboard page that needs multiple queries run to fill it in. So I have my model that has multiple queries. My questions is how do I pass those queries to the view?

Is this how? (where $data and $requests are two different queries)

Code:
$this->load->view('myview', $data, $requests);

That doe not seem to work but I don't know if that is my problem or if I have a mistake someplace else?

I looked in the user guide but did not find an answer.

Thanks for any help you can offer.

Rich
#2

[eluser]Kosonome[/eluser]
Code:
$data['request1'] = 'something';
$data['request2'] = 'other thing';

In view you need:
Code:
<?php echo $request1; ?>
<?php echo $request2; ?>
#3

[eluser]rogierb[/eluser]
You pass an array to the view. What is part of that array is up to you.

Code:
$data['string'] = "something";
$data['my_array'] = array("a","b","c");
$data['result_object'] = $this->my_model->my_custom_query($somevar)

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

And in your view you can access these as variables

Code:
echo $string;
print_r($my_array);

if($result_object->num_rows()>0)
{
//do something
} else echo "No data found";
#4

[eluser]rich.a.coy[/eluser]
Thanks for your quick replies. It's starting to make sense to me. Smile

So where you have

Code:
// do something

What syntax is needed to pull the values out each of the arrays? Say for example, the title value in the result_object array?
#5

[eluser]rich.a.coy[/eluser]
I figured it out! Thanks for your help.




Theme © iAndrew 2016 - Forum software by © MyBB