I'm trying to use this script for searching more then one words at a time from a database. Now the problem is that my script only search one word once. But i want to search more words at once like (quick home jquery) if the database contains those words, then it will show the result. How could I do this with this script can any body tell me? or how could i search any keyword ? please help me...
<?php
include_once ('database_connection.php');
if(isset($_GET['keyword'])){
$keyword = trim($_GET['keyword']) ;
$keyword = mysqli_real_escape_string($dbc, $keyword);
$query = "select topictitle,topicdescription from topics where topictitle like '%$keyword%' or topicdescription like '%$keyword%'";
//echo $query;
$result = mysqli_query($dbc,$query);
if($result){
if(mysqli_affected_rows($dbc)!=0){
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)){
echo '<p> <b>'.$row['topictitle'].'</b> '.$row['topicdescription'].'</p>' ;
}
}else {
echo 'No Results for :"'.$_GET['keyword'].'"';
}
}
}else {
echo 'Parameter Missing';
}
?>
Explode the search term so you get an array with each word and construct the query like that? The question is a bit confusing, probably something like this might work for you:
if(isset($_GET['keyword'])){
$keyword = trim($_GET['keyword']);
$keyword = mysqli_real_escape_string($dbc, $keyword);
$search_terms = explode(" ",$keyword);
$query = "select topictitle,topicdescription from topics where 1 ";
foreach($search_terms as $searchterm){
$query = $query."or topictitle like '%".$searchterm."%' or topicdescription like '%".$searchterm." ';
}
...