Help me traverse my query database result into each row and each column?

#1
[eluser]Edy S[/eluser]
Hi, im new in codeIgniter, now that i have the problem to traverse my query result . here is my code i juts try to learn :
This is the code of my Blogmodel
Code:
<?php

class Blogmodel extends CI_Model {

    var $title   = '';
    var $content = '';
    var $date    = '';

    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
    
    function get_last_ten_entries(){
        $query = $this->db->get('sys_prmpost', 10);
        return $query->result_array();
    }

And this is the code in my controller called blog

Code:
<?php
class Blog extends CI_Controller {

    public function index(){
        
    }
    //---------------------------------------------------------------
    //display latest ten post
    //---------------------------------------------------------------
    public function post(){
        $data['page_title'] = "Our list posted tutorials";
                
        $this -> load->model('Blogmodel');
        $data['post']    = $this -> Blogmodel ->get_last_ten_entries();
        $this -> load->view('post',$data);
    }
    
}
?>

Then my problem is how to traverse result from
Code:
$data['post']    = $this -> Blogmodel ->get_last_ten_entries();
in my views. I means that my table is contain with column postID,Title,Details.
Then what should i do if i want to use each column, for example if i want to use it in the link :
Code:
http://example.com/index.php/blog/my_post_id_here

Thanks for everybody who can help resolve my problem...

#2
[eluser]jmadsen[/eluser]
it's an array, Edy, so just use a foreach statement in your view is fine


i.e.,

Code:
<?php

if (!empty($post)){
    foreach ($post as $p){
       //do my blah here
    }

}
?>


(if a mod reads this,can you move to the correct area?)

#3
[eluser]Edy S[/eluser]
Thanks jmadsen, well my problem havebeen resolved now...
I'm so sorry i just new in this forum, so that i dont really know where should i post my problem.. Big Grin


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.