[eluser]Ayelius Maximous[/eluser]
Hi guys. I have a table to store Categories and a page to add category. in the add category page I have to display categories too.
Controller :
Code:
class Products extends CI_Controller {
function __construct(){
parent::__construct();
}
function Categories ($message=NULL){
$data = array(
'categories' => $this->Categories_Model->get_categories(),
'category-title' => $this->input->post('category-title'),
'description' => $this->input->post('description'),
'parent' => $this->input->post('parent'),
'message' => $message
);
$this->load->library('form_validation');
$this->form_validation->set_rules('category-title', 'Category Title', 'required');
$this->form_validation->set_rules('description', 'Description', 'required');
if ($this->form_validation->run() == FALSE) {
$this->load->view('Admin/Header');
$this->load->view('admin/template');
$this->load->view('admin/Categories', $data);
$this->load->view('Admin/Footer');
}
else {
if ($this->Categories_Model->add()) {
$this->load->view('Admin/Header');
$this->load->view('admin/template');
$this->load->view('admin/Categories', $data);
$this->load->view('Admin/Footer');
}
}
}
}
Model :
Code:
class Categories_Model extends CI_Model {
function __construct() {
parent::__construct();
}
function get_categories() {
$query = $this->db->get('categories');
if ($query->num_rows() > 0)
{
$te = $query->num_rows();
foreach ($query->result_array() as $row){
$row = $query->row();
echo $row->title;
echo $row->description;
}
return $row;
} else
return "<option value='0'>Parent</option>";
}
View :
Code:
<table cellspacing=0 cellpadding=9 width='50%' >
<tr>
<th>Category</th>
<th>Description</th>
<th>Amount</th>
</tr>
<tr>
<td class='td-mid'><b><?php echo "$categories->title"; ?></b></td>
<td class='td-mid'><?php echo "$categories->description"; ?></td>
<td class='td-mid'><?php echo "$categories->amount"; ?></td>
</tr>
</table>
it just display one record, not all of them.
what have I to do ?