嗨大家因为某种原因我的搜索功能不起作用了我已经尝试过各种各样的/或_似无济于事有人请帮忙在这里是我的控制器代码:
function contractor(){
$keyword = $this->input->post('keyword');
$this->db->like($keyword);
$this->db->like('contractor_location',$keyword);
$this->db->like('contractor_email',$keyword);
$this->db->like('contractor_description',$keyword);
$this->db->like('contractor_number',$keyword);
$this->db->like('contractor_website',$keyword);
$this->db->join('category','contractors.contractorID=category_name.catagory_id','inner');
$this->db->group_by('contractor.contractorID');
$query = $this->db->get('contractors');
return $query->result();
}
更新: 这是我收到的错误消息抱歉我忘了添加它:
A Database Error Occurred
Error Number: 1064
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near 'LIKE '%%' ESCAPE '!' AND `contractor_location` LIKE '%%' ESCAPE
'!' AND `contr' at line 4
SELECT * FROM `contractors` INNER JOIN `category` ON
`contractors`.`contractorID`=`category_name`.`catagory_id` WHERE LIKE
'%%' ESCAPE '!' AND `contractor_location` LIKE '%%' ESCAPE '!' AND
`contractor_email` LIKE '%%' ESCAPE '!' AND `contractor_description`
LIKE '%%' ESCAPE '!' AND `contractor_number` LIKE '%%' ESCAPE '!' AND
`contractor_website` LIKE '%%' ESCAPE '!' GROUP BY
`contractor`.`contractorID`
Filename: modules/search/models/Search_m.php
Line Number: 38
答案 0 :(得分:2)
您的代码未命名列名称
class Kaushal28 {
public Number add(Number a, Number b){
return a.doubleValue() + b.doubleValue();
}
public CharSequence add(CharSequence a, CharSequence b){
StringBuilder sb = new StringBuilder(a.length() + b.length());
return sb.append(a).append(b).toString();
}
}
表连接中有错误
$this->db->like($keyword);
更正后的代码:
$this->db->join('category','contractors.contractorID=category_name.catagory_id','inner');
答案 1 :(得分:1)
缺少列名
del df.column_name
您需要更正此行WHERE LIKE '%%' ESCAPE '!'
答案 2 :(得分:0)
最终工作守则如下:
function contractor(){
$keyword = $this->input->post('keyword');
$location = $this->input->post('location');
$industry = $this->input->post('industry');
$this->db->like('contractor_name',$keyword,$industry,$location);
$this->db->like('contractor_location',$keyword,$industry,$location);
$this->db->like('contractor_email',$keyword,$industry,$location);
$this->db->like('contractor_description',$keyword,$industry,$location);
$this->db->like('contractor_number',$keyword,$industry,$location);
$this->db->like('contractor_website',$keyword,$industry,$location);
$this->db->join('catagory','contractors.contractorID=catagory.ID','inner');
$this->db->group_by('contractors.contractorID');
$query = $this->db->get('contractors');
return $query->result();
}