Ok to start things off, I am doing a revamp on a custom PHP CMS and the client wants the search function to do the following:
Lets say a user searches for "WIX 24061" the current search function will mark that as not found and forward to the notfound page but when i search for "24061" it pulls it up.
So what I decided i would do is an explode to a var and use a LIKE SQL query. But it is not working. Heres a snippet of the code that will should be working but its not.
$whereExtra = '';
if(!empty($_SESSION['search']))
{
if(strpos($_SESSION['search'], ',') !== false)
{
$parts1 = explode(',', $_SESSION['search']);
for($i = 0; $i < count($parts1); $i++){
$whereExtra .= " AND (cp.sku LIKE '%" . $parts1[$i] . "%' OR cp.description LIKE '%" . $parts1[$i] . "%') ";
}
}
else
{
$whereExtra = " AND (cp.sku LIKE '%" . $_SESSION['search'] . "%' OR cp.description LIKE '%" . $_SESSION['search'] . "%') ";
}
I have also tried the following:
$whereExtra = '';
if(!empty($_SESSION['search']))
{
if(strpos($_SESSION['search'], ',') !== false)
{
$parts1 = explode(',', $_SESSION['search']);
foreach($parts1 as $p)
$whereExtra .= " AND (cp.sku LIKE '%" . $p . "%' OR cp.description LIKE '%" . $p . "%') ";
}
else
{
$whereExtra = " AND (cp.sku LIKE '%" . $_SESSION['search'] . "%' OR cp.description LIKE '%" . $_SESSION['search'] . "%') ";
}
}
Any Ideas?