Welcome Guest, Not a member yet? Register   Sign In
How to fetch multy records
#1

[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>&lt;?php echo "$categories->title"; ?&gt;</b></td>
  <td class='td-mid'>&lt;?php echo "$categories->description"; ?&gt;</td>
  <td class='td-mid'>&lt;?php echo "$categories->amount"; ?&gt;</td>
</tr>
</table>

it just display one record, not all of them.

what have I to do ?


Messages In This Thread
How to fetch multy records - by El Forum - 08-17-2012, 11:51 AM
How to fetch multy records - by El Forum - 08-17-2012, 01:42 PM
How to fetch multy records - by El Forum - 08-17-2012, 02:05 PM
How to fetch multy records - by El Forum - 08-17-2012, 02:14 PM
How to fetch multy records - by El Forum - 08-17-2012, 02:51 PM
How to fetch multy records - by El Forum - 08-17-2012, 03:02 PM
How to fetch multy records - by El Forum - 08-17-2012, 03:06 PM
How to fetch multy records - by El Forum - 08-17-2012, 03:12 PM



Theme © iAndrew 2016 - Forum software by © MyBB