Welcome Guest, Not a member yet? Register   Sign In
Query from view
#1

[eluser]greenba[/eluser]
Hello,

I have query that runs in the controller:
Code:
$data['query'] = $this->Member->select_sql($id);    
    $this->load->view('myform');

and then outputs data in the view:

Code:
foreach ($query->result() as $row):
   echo $row->post_title;
   echo $row->post_user_id;
endforeach;

So this outputs me a list of posts made by a user. Now I would like to run one more query that would for each post loop through my user table and output user information next to each post. (I dont want to select data from a view or joint those 2 tables at this time in MySQL)

Any ideas?
#2

[eluser]jamziee[/eluser]
Is the list based around one user?
#3

[eluser]greenba[/eluser]
No. there are many users.
#4

[eluser]jamziee[/eluser]
dose the information about the user haft to be on the same page?
#5

[eluser]greenba[/eluser]
Yes it does.
#6

[eluser]jamziee[/eluser]
you select all the users from you database. pass it through to the view and then select which one you want for each post, this could be a bit uneficiant though. But work
#7

[eluser]Colin Williams[/eluser]
1. Use a JOIN query to get all the data you need.
2. In the model after the query, iterate over the result, grouping multiple values. You should end up with a multidimensional array of posts, where each post has a user property that is an object containing the user data
3. Pass this on to the view

This is a basic workflow. If you don't know how joins work, or how to manipulate arrays, I would suggest you go back to square one and do some reading on each of those topics.




Theme © iAndrew 2016 - Forum software by © MyBB