Welcome Guest, Not a member yet? Register   Sign In
Fetching db details displaying in a table dynamicalls
#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;


Messages In This Thread
Fetching db details displaying in a table dynamicalls - by El Forum - 08-25-2010, 10:52 PM
Fetching db details displaying in a table dynamicalls - by El Forum - 08-26-2010, 12:28 AM



Theme © iAndrew 2016 - Forum software by © MyBB