Welcome Guest, Not a member yet? Register   Sign In
Fetching db details displaying in a table dynamicalls
#1

[eluser]oldrock[/eluser]
Hi..,

I m new to code igniter , the issue is i m unable to fetch the multiples rows from a database using model and diplay the data in the view in a table structure dynamically could anybody plz help me with the sample code.

thanks in advance
#2

[eluser]WanWizard[/eluser]
Controller:
Code:
class Test Extends Controller
{
    function Test()
    {
        parent::Controller();
    }

    function index()
    {
        // data array for the view
        $data = array();

        // load the model
        $this->load->model('my_model');

        // fetch the rows
        $data['rows'] = $this->my_model->get_rows();

        //show the view
        $this->load->view('my_view', $data);
    }
}

Model:
Code:
class My_model Extends Model
{
    function My_model()
    {
        parent::Model();
    }

    function get_rows()
    {
        // fetch the rows
        $query = $this->db->get('table');

        // return the result
        if ( $query )
        {
            return $query->result();
        }
        else
        {
            return FALSE;
        }
    }
}

View:
Code:
<?php if ( $rows ) { ?>
    <table>
    &lt;?php foreach ($rows as $row) { ?&gt;
        <tr>
            <td>&lt;?=$row->field ?&gt;</td>
        </tr>
    &lt;?php } ?&gt;
    </table>
&lt;?php } ?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB