The problem is that it displays all the rows from db instead of displaying only those rows which contain search keywords: Please help me.
public function search($data)
{
$name = $data["name"];
$surname = $data["surname"];
$this->db->select('*');
$this->db->from('workers');
$this->db->like('name', '%' . $name . '%');
$this->db->or_like('surname', '%' . $surname . '%');
$query = $this->db->get();
Bookmark this question. Show activity on this post. $ENROLLEES = $this->load->database('ENROLLEES', TRUE); $ACCOUNTS = $this->load->database('ACCOUNTS', TRUE); $SELECT = "SELECT $ACCOUNTS.
CodeIgniter gives you access to a Query Builder class. This pattern allows information to be retrieved, inserted, and updated in your database with minimal scripting. In some cases only one or two lines of code are necessary to perform a database action.
You can use below mentioned query. $query = $this->db->group_by('category_master. Category_Id,business_profile_details. Business_Id');
You wrote CI like query wrong way.Look the documentation how to write it properly
Your query should be like this.No need to add %
. CI add them if you do not pass 3rd parameter of like function.
$this->db->select('*');
$this->db->from('workers');
$this->db->like('name', $name);
$this->db->or_like('surname', $surname);
$query = $this->db->get();
Better do with some valid data like this.
$this->db->select('*');
$this->db->from('workers');
if($name)
{
$this->db->or_like('name', $name);
}
if($surname)
{
$this->db->or_like('surname', $surname);
}
$query = $this->db->get();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With