[eluser]JaRoLLz[/eluser]
CI use MVC. So, you should separate your app into model, view, controller.
As for that function, you should split it into M,V,C.
[model] In job_model, create a function to get the `cats` data then return an array that contains its data
[view] in a view file (e.g. subcat.php), create a layout to present the data
[controller] in your controller (e.g. Cats) create a function that will get data using the model then passing it to view file to show.
crude example:
MODEL: job_model.php
Code:
class Job_model extends Model {
function Job_model() {
parent::Model();
}
function getCats() {
$query = $this->db->query('
SELECT *
FROM `cats`
');
if ($query->num_rows() > 0) {
return $query->result_array();
} else {
return array();
}
}
}
VIEW: subcat.php
Code:
<html>
<body>
<h1>Cats</h1>
<? foreach ($catdata as $r): ?>
ID: <?php echo $r['id'] ?>
Name: <?php echo $r['name'] ?>
Desc: <?php echo $r['desc'] ?>
<br>
<? endforeach; ?>
</body>
</html>
CONTROLLER: cats.php
Code:
class Cats extends Controller {
function Cats() {
parent::Controller();
}
function populate() {
$this->load->model('job_model');
$data['catdata'] = $this->job_model->getCats();
$this->load->view('subcat',$data);
}
}
p.s.: Adjust the code as needed. CMIIW!