Forum Moderators: coopster
$q = $_GET['q'];
if ($q) {
$q = strtolower($q);
$k = split(" ", $q);
$num_keywords = count($k);
for ($i=0; $i<$num_keywords; $i++) {
if ($i) {
$search_string .= "OR moviename LIKE '%" . $k[$i] . "%' "; }
else {
$search_string .= "moviename LIKE '%" . $k[$i] . "%' "; }
} end for
$and .= "WHERE ($search_string) ";
} //end if$querycount = "SELECT * FROM titles $and";
rest of code...
This works ok, but if I type something in like 'The Killer' it fetches everything with the word 'the' as well.
I have put the words into an array that I want to filter out.
$skipwords = array("the", "of", "and"); etc
Can I use that to filter out the words? I`ve been playing around with the in_array() function, but can`t seem to get it to work like I want it to.
Any help you could give me would be appreciated.
Thank you.
$q = $_GET['q'];
if ($q) {
$q = strtolower($q);
$k = split(" ", $q);
$num_keywords = count($k);
foreach ($k as $d) {
$count=0;
if (!in_array($d, $skipwords)) {
$words[] = $d;
$count=$count+1;
}
}
for ($i=0; $i<$count; $i++) {
if ($i) {
$search_string .= "OR moviename LIKE '%" . $words[$i] . "%' "; }
else {
$search_string .= "moviename LIKE '%" . $words[$i] . "%' "; }
} //end for
$and .= "WHERE ($search_string) ";
} //end ifif ($count>0)
{
$querycount = "SELECT * FROM titles $and";
}rest of code...
Seems to work ok anyway. :)
$skipwords = array("the", "and", "is", "are", "to");
$q = $_GET['q'];
if ($q) {
$q = strtolower($q);
$k = split(" ", $q);
$num_keywords = count($k);
$count=0;
foreach ($k as $d) {
if (!in_array($d, $skipwords)) {
$words[] .= $d;
$count=$count+1;
}
}
for ($i=0; $i<$count; $i++) {
if ($i) {
$search_string .= "OR moviename LIKE '%" . $words[$i] . "%' "; }
else {
$search_string .= "moviename LIKE '%" . $words[$i] . "%' "; }
} //end for
$and .= "WHERE ($search_string) ";
} //end if
if ($count>0)
{
$querycount = "SELECT * FROM titles $and";
}rest of code...
:)