Reputation: 497
I have a search form built in my website's header (I'm using Bootstrap as well). The purpose of the form is to query users, based on the input.
View
<form class="navbar-form pull-right" method="post" action="updates/search" name="search">
<input type="text" class="input-medium" size="50" placeholder="Search for users" style="padding-left:10px">
<button type="submit" class="btn btn-small" name="sub">Search</button>
</input>
</form>
Model
function get_search($input)
{
$this->db->like('username',$input);
$query = $this->db->get('users');
print_r($query->result()); // for now i am just printing the results, in the future i will simply return this
}
Controller
public function index($renderData="")
{
$this->load->model("user_model");
$this->load->model("updates_model");
$this->_render('pages/search');
}
When I run a search query, say "as;fa;sklfl;kasf", it still prints all of the usernames in the database (5), instead of a blank page. Is my get_search method not finding the $input variable for some reason?
Edit: I fixed it. I had the value in the form, not in the input
Upvotes: 0
Views: 101
Reputation: 2042
your text box not given any name
<input type="text" class="input-medium" size="50" placeholder="Search for users" style="padding-left:10px" />
to
<input type="text" name ="username" class="input-medium" size="50" placeholder="Search for users" style="padding-left:10px"/>
Then use your Query like-
$input = $this->input->post('username');
$this->db->like('username',$input);
$query = $this->db->get('users');
Upvotes: 1
Reputation: 4527
function get_search($input)
{
//you might want to add `%` on your like statement just add both/after/before the third paraeter
$this->db->like('username',$input,'BOTH');
$query = $this->db->get('users');
//check the query
print_r($this->db->last_query());
}
Upvotes: 0
Reputation: 2009
$this->db->like('username',$input);
$query = $this->db->get('users');
Where is the association of your like query with the variable $query?
You tell your framework to get all users and set it to $query.
$query = $this->db->get('users');
Upvotes: 0