CodeIgniter Forums
a bit of logic help wanted - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: a bit of logic help wanted (/showthread.php?tid=27546)



a bit of logic help wanted - El Forum - 02-14-2010

[eluser]DumpProgrammer[/eluser]
I have a variable in my controller that I call three times on my home page but I would like it to have different articles showing up on my page rather than have the same items three times. Here is the code
Code:
$data['post'] = $this->MPosts->getAllActivePosts();
. So have been retrieving the active post on website with some with pictures and some just the headings. What I would like to have is a start and limit so that there is a continuation of the mysql query on the three articles on the page because its news so I cannot have the same four topics showing. So do I have to perform the same query with different parameters or do I have to use a different variable for my articles?


a bit of logic help wanted - El Forum - 02-14-2010

[eluser]markup2go[/eluser]
You want to look in your model and update the query in getAllActivePosts(). Post this function if you need help with that.


a bit of logic help wanted - El Forum - 02-15-2010

[eluser]DumpProgrammer[/eluser]
here is the controller
Code:
function index()
    {
  
    $data['cats'] = $this->MCats->getTopCategories(); //we will replace soon!
    $data['title'] = "Shout-Africa";
    $data['main'] = 'public_home';
    $data['featured'] = $this->MPosts->getAllFeaturedPosts();
    $data['post'] = $this->MPosts->getAllActivePosts();
    $data['comms'] = $this->MComments->getLatestComments();    
    $this->load->vars($data);
    $this->load->view('newheader');
    $this->load->view('newnav');
    $this->load->view('newfeatured');    
    $this->load->view('newcontent');
    $this->load->view('newvideo');
    $this->load->view('newrightside');
    $this->load->view('newwidget');
    $this->load->view('footer');

    }
and here is the model
Code:
function getAllActivePosts(){
     $data = array();
     $this->db->limit(4);
     $this->db->where('status', 'published');
     $Q = $this->db->get('posts');
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
    }
    $Q->free_result();  
    return $data;
}
I hope that helps.