Welcome Guest, Not a member yet? Register   Sign In
Urgent!, urgent!, emerrrgency! creating two separate querys and passing their results to a view file
#1

[eluser]prog_boy[/eluser]
Quote:I really like cookies and milk while i post to my blog!
Posted on wednesday Aug 9th, 2006 @ 5:20PM -by Prog Boy

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent aliquam, justo convallis luctus rutrum, erat nulla fermentum diam, at nonummy quam ante ac quam. Maecenas urna purus, fermentum lacus...

As you can see from the text above, that is what the goal of my query is. In my controller I want to select everything from the blogs table and the members table. I want to echo the results from the blog table in my view file(i.e $blog->title,dateposted,author, etc...), i want the name field of the members table to be echo in the view file where the blogs member id field is equals to the member id field on the members table. how do i go about this CI? this problem has almost brought me to tears, it's so frustrating >Sad that i feel like giving up.
#2

[eluser]Eric Barnes[/eluser]
function my_controller()
{
$data['blog'] = $this->blog_model->get_post();
$this->load->view('my_view', $data);
}

# View
echo $blog->title;
#3

[eluser]prog_boy[/eluser]
#Controller
Code:
function entries()
    {
        $data['blog']= $this->db->get('blogs');
        
        $this->load->view('entries',$data);
    }
#View
Code:
<?php foreach($blog->result() as $row):?>
        <h3>&lt;?=$row->title?&gt;</h3>
        <p class="date">Posted on &lt;?=date("l M jS, Y ".'@'." g:iA",strtotime($row->dateposted))?&gt;
        -by //This is where the problem is, the member_id is displayed
//but i really want the members name to display
//WHERE this member_id corresponds to the id field in the members table.
        &lt;?=$row->member_id;?&gt;
        </p>
    &lt;?php endforeach;?&gt;
Creating the SQL is no problem but passing it to the view is killing me.
#4

[eluser]KingSkippus[/eluser]
#Controller
Code:
function entries()
    {
        $this->db->from('blogs');
        $this->db->join('members', 'blogs.member_id = members.id');
        $data['blog'] = $this->db->get();
        
        $this->load->view('entries',$data);
    }

#View
Code:
&lt;?php foreach($blog->result() as $row):?&gt;
        <h3>&lt;?=$row->title?&gt;</h3>
        <p class="date">Posted on &lt;?=date("l M jS, Y ".'@'." g:iA",strtotime($row->dateposted))?&gt;
        -by &lt;?=$row->name;?&gt;
        </p>
&lt;?php endforeach;?&gt;

...Assuming the column of the member's name in the members table is "name," of course. If it's something like "member_name," just plug in whatever it is instead of $row->name.
#5

[eluser]prog_boy[/eluser]
Wow! you're a genius. thanks a lot. it works perfect.




Theme © iAndrew 2016 - Forum software by © MyBB