[eluser]Henry Weismann[/eluser]
I need a model to grab results based on a where clause but when the variable (customer_id) of the where clause is not given I want it to give an empty result set.
Should I be checking whether customer_id is empty before running the model function and if it is set $data to an empty quote or can I have the model take the empty variable and return an empty set.
The problem is if customer_id is empty when it is sent to the model function the whole table is returned as a result.
Model:
Code:
function get_stores($customer_id, $limit,$offset)
{
$this->db->where('customerName', $customer_id);
$this->db->limit($limit,$offset);
$query = $this->db->get('storeinfo');
return $query->result();
}
Controller
Code:
function moviesSold($invoice_id, $limit = 20, $offset = 0)
{
$customer_id = $this->customer_id ? $this->customer_id : $this->uri->segment(4);
$data['store'] = $this->Customer_model->get_stores($customer_id,75,0);
.................................
................
..........
.....
..
.
How should I do this.