how to get data from database throught model using codeigniter with for each loop -
http error occured while calling data model using function
model
public function getproductcombo() { $q = $this->db->get_where('products', array('type' => 'combo')); if ($q->num_rows() > 0) { foreach (($q->result()) $row) { $data[] = $row; } return $data; } }
controller
function sets() { $this->sma->checkpermissions(); $this->load->helper('security'); $this->data['error'] = (validation_errors() ? validation_errors() : $this->session->flashdata('error')); // problem in line $this->data['showcombo'] = $this->load->sales_model->getcomboproduct(); $bc = array(array('link' => base_url(), 'page' => lang('home')), array('link' => site_url('sales'), 'page' => lang('products')), array('link' => '#', 'page' => "sets") ); $meta = array('page_title' => "add sets", 'bc' => $bc); $this->page_construct('sales/sets', $meta, $this->data); }
first of all, no need include curly braces $q->result
foreach ($q->result $row) { $data[] = $row; }
no need use validation_errors in php
file.you can directly load form
page.use validation_errors()
in view page.
in controller, this
if ($this->form_validation->run() == false) { $this->load->view('myform'); }
then in formpage
can echo
<?php echo validation_errors(); ?>
Comments
Post a Comment