Reputation: 1320
I'm attempting to pass a model an argument, which is passed in from the controller. So in the URL if I enter the url www.foobar.com/report/ecomma/ford
('report' is controller name, 'ecomma' the function 'ford' the argument), I'm expecting the controller to pass the model the argumnet 'ford'
the model should then perform the sql query with the argument passed in to it, LIKE "%$brand%"";
.
I have the following controller (called report):
public function ecomma($brand){
$this->load->model('report_model');
$data ['query'] = $this->report_model->generate_brand_data_report($brand);
$this->load->view('brand_report_view',$data);
}
}
The model associated with the controller is here:
public function generate_brand_data_report($brand = ''){
$sql = "SELECT
DISTINCT pd_model_code AS `Model_SKU`,
pd_model_description AS `Model_Title`
FROM iris_product_data
WHERE pd_vendor LIKE "%$brand%"";
$query = $this->db->query($sql);
return $query->result();
}
The argument is not passed in however, can anyone see the issue here?
Upvotes: 1
Views: 54
Reputation: 22532
In Active Record you can write your query as
$this->db->distinct('pd_model_code AS Model_SKU');
$this->db->select('pd_model_description AS `Model_Title`');
$this->db->like('pd_vendor',$brand);
$query=$this->db->get('iris_product_data');
Upvotes: 2
Reputation: 7023
you can't use double quotation inside double quotation you can use single or double like this:
$sql = "SELECT
DISTINCT pd_model_code AS `Model_SKU`,
pd_model_description AS `Model_Title`
FROM iris_product_data
WHERE pd_vendor LIKE \"%$brand%\"";
or
$sql = "SELECT
DISTINCT pd_model_code AS `Model_SKU`,
pd_model_description AS `Model_Title`
FROM iris_product_data
WHERE pd_vendor LIKE '%$brand%'";
Upvotes: 1