Welcome Guest, Not a member yet? Register   Sign In
Display both name catagories and entries
#4

[eluser]kieutuan[/eluser]
Table Catagories (id, name)
Table Entries (id, cat_id, title, body)


Model
Code:
<?php
class Site_model extends Model{
    function Site_model()
    {
        parent::Model();
    }
    
    function get_records(){
        $this->db->order_by('id', 'desc');
        $query = $this->db->get('catagories');
        return $query->result();
    }
}
?>

Controllers
Code:
<?php
class Home extends Controller
{
    function index()
    {    
            $this->load->model('site_model');
        
        if($query = $this->site_model->get_records())
        {
            $data['records'] = $query;
        }
        
        $this->load->view('include/contents', $data);
    }
}
?>


View
Code:
<?php foreach($records as $rows): ?>
<h1>Catagories: &lt;?=$rows->name?&gt;</h1>
   &lt;?php
   $entries = $this->db->get_where('entries', array('cat_id'=>$rows->id));
   foreach($entries->result() as $entries_row):
   ?&gt;
   <h2>&lt;?=$entries_row->Title?&gt;</h2>
   <p>&lt;?=$entries_row->body?&gt;</p>
   &lt;?
   endforeach;
   ?&gt;
&lt;?php endforeach; ?&gt;


I want write query to get entries in Model or Controllers
how do write it?


Messages In This Thread
Display both name catagories and entries - by El Forum - 09-25-2010, 09:54 AM
Display both name catagories and entries - by El Forum - 09-25-2010, 01:46 PM
Display both name catagories and entries - by El Forum - 09-25-2010, 04:11 PM
Display both name catagories and entries - by El Forum - 09-25-2010, 08:22 PM
Display both name catagories and entries - by El Forum - 09-25-2010, 08:29 PM
Display both name catagories and entries - by El Forum - 09-25-2010, 09:21 PM
Display both name catagories and entries - by El Forum - 09-26-2010, 06:55 AM
Display both name catagories and entries - by El Forum - 09-26-2010, 07:29 AM



Theme © iAndrew 2016 - Forum software by © MyBB