Welcome Guest, Not a member yet? Register   Sign In
Best way of listing a table
#3

[eluser]cb951303[/eluser]
[quote author="stuffradio" date="1220842397"]No you need to take a look at Models.

In a model it is really easy to get results from a Database. For what you are doing this is what you do.

Controller:
Code:
<?php

class Mycontroller extends Controller
{

  function Mycontroller()
  {
    parent::Controller();
    $this->load->library('database');
    $this->load->model('Mymodel');
  }

  function index()
  {
    $layout['list'] = $this->Mymodel->listResults();
    $this->load->view('header');
    $this->load->view('main', $layout);
    $this->load->view('footer');
  }

}

Model:
Code:
<?php

class Mymodel extends Model
{

  function Mymodel()
  {
    parent::Model();
  }

  function listResults()
  {
    $query = $this->db->get('table');
    return $query->result();
  }

}


View:

Code:
<h1>Results</h1>
&lt;?php foreach($list as $result): ?&gt;
&lt;?php echo $result->field . '<br />'; ?&gt;

I hope this helps you better understand what to do Smile[/quote]
Actualy I'm fully aware of models and MVC design criteria. but what I 'm asking has nothing to do with models. my listResults function uses CI HTML table class to create a table. it ofcourse gets its content via a model but as I said earlier it has nothing to do with the original question. thanks anyway


Messages In This Thread
Best way of listing a table - by El Forum - 09-07-2008, 12:41 PM
Best way of listing a table - by El Forum - 09-07-2008, 03:53 PM
Best way of listing a table - by El Forum - 09-07-2008, 04:21 PM



Theme © iAndrew 2016 - Forum software by © MyBB