i tried to use the jquery autocomplete feature uisng php,mysql,but the problem is that the sql query get all records in the table and not the only rows that match the searched word
what's the problem in this query,it get all records and not the specified one
php code:
if(isset($_POST['search_word']) && $_POST['search_word'] != ''){
$q_title=$db->real_escape_string($_POST['asktitle']);
$search_q=$db->query("select * from stack_ask where q_title like '%$q_title%' order by id desc limit 5 ");
echo $search_q->num_rows;
while($row=$search_q->fetch_assoc()){
$row_title=$row['q_title'];
?>
<div class="display_box" align="right">
<a href="question?id=#" target="_blank"><?php echo $row_title; ?></a>
</div>
<?php
}
}else{
}
js
//autosuggestion
$('#asktitle').keyup(function(){
var search_word = $(this).val();
if(search_word.length > 4){
$('#search_box').css({'display':'block'});
$.ajax({
type: 'POST',
data: 'search_word='+search_word,
url: 'includes/process_autosuggest.php',
beforeSend: function(){
$('#search_load').css({'display':'block'});
},
success: function(data){
$('#search_load').css({'display':'none'});
if(data == 1){
$('#result_s').text('Searching 0 results .');
}else {
$('#result_s').html(data);
}
}
});
}else {
$('#search_box').fadeOut('fast');
}
});
$('#asktitle').blur(function(){
$('#search_box').fadeOut('fast');
});
form:
<form method="POST" action="" id="postproject" >
<input dir="rtl" id="asktitle" name="asktitle" type="text" autocomplete="off" placeholder="ضع عنوان مناسب لسؤالك" class="validate[required,maxSize[50]] text-input" required>
</form>