Codeigniter LIKE search always returns the whole table
When I the search function, no matter what I get back all the entries in the searched DB table.
This is the controller:
function search()
{
$this->form_validation->set_rules('company', 'company field', 'required');
$search_text = $this->input->post('name');
$is_ajax = $this->input->post('ajax');
$data['found_companies'] = $this->Company->get_companies_by_name($search_text);
$data['page_title'] = 'Search';
$this->load->view('head', $data);
$this->load->view('pages/search', $data);
$this->load->view('footer');
}
this is the model function get_companies_by_name
that does the search:
function get_companies_by_name($name) {
$this->db->select('id,name,logo,phone,email,adress,url,contact,contact_phone,biz_id,join_date,user,password');
$this->db->like('name', $name, 'after');
$returned = $this->db->get('companies');
return $returned;
}
and this is the view part that displays the search:
<?php
validation_errors();
echo form_open("pages/search",$attributes);
echo form_input('company','');
echo form_submit('submit','חפש');
echo form_close();
foreach ($found_companies->result() as $company) { ?>
<?= img("uploads/thumbs/" . $company->logo);?>
<?= $company->id; ?>
<?= anchor ("admin/home/$company->id", "$company->name</br>"); ?>
<?= $company->phone;?>
<?=开发者_JS百科 $company->email;?>
<?= $company->adress;?>
<?= $company->url;?>
<?= $company->contact;?>
<?= $company->contact_phone;?>
<?= $company->biz_id;?>
<?= $company->join_date;?>
<?= $company->user;?>
<?= $company->password;?>
<?= anchor ("bizadmin/del/$company->id", "מחק עסק</br>")." ".anchor ("admin/edit/$company->id", "ערוך עסק</br>")." ".anchor ("admin/editcamp/$campaign_id->id", "ערוך קמפיין</br>"); ?>
</br>
<? } ?>
Try changing
$search_text = $this->input->post('name');
with
$search_text = $this->input->post('company');
in function search()
精彩评论