Page 1 of 1

White space in searches

Posted: Tue Jun 09, 2009 5:47 am
by bk1984
Hi all,

I am currently trying to fix the search on a website I am trying to develop. What happens is if you search for 'bin' a lot of products come up which contain bin within their product description, this is very annoying as you can imagine because things like post it notes will appear which are totally unrelated.

But when I add spaces into the the search for example (space)bin(space) it will come up with the correct products. I am baffled I have search through the code numerous times and just don't know how to do it. I am a beginner at PHP but hoping to quickly learn so I can get the website running functionally how everyone wants it.

the code is:

Code: Select all

<?php 
 
$app       = $this->globals('khxc_display.app');
$eol       = $this->globals('khxc.eol');
$formid    = $app . '--minisearch';
$strid     = $app . '--prodsearch--string';
$link      = $this->link_namespace($app,'prodsearch',array());
$typeid    = $app . '--prodsearch--type';
$cgi_value = '';
 
$this->xhtml_quickform_header($formid,$app,'prodsearchp',array());
 
print '<p class="hidden"><label for="' . $app . '--minisearch--' . $strid . '"';
print '>Search Term</label></p>' . $eol;
 
print '<p class="inline"><input class="khxc_quickfield" type="text" name="' . $strid;
print '" id="' . $app . '--minisearch--' . $strid . '" value="';
print $cgi_value . '" size="22" maxlength="100" /></p>' . $eol;
 
print '<p class="hidden"><input class="khxc_quickfield" type="text" value="EXACT" name=" ' . $typeid;
print '" id="' . $app . '--minisearch--' . $typeid . '" value="ALL" /></p>' . $eol;
 
$this->xhtml_quickform_footer($formid,'Online Store Search',1);
 
print '<a class="unfancy" href="' . $link . '" title="Advanced Search">Advanced Search</a>' . $eol;
?>
any help would be extremely appreciated

Re: White space in searches

Posted: Tue Jun 09, 2009 6:01 am
by bk1984
Sorry didn't even say what I wanted to do ooops, what I want to do is add the spaces automatically so the user doesn't have to. so it would be (space) bin (space) or (space)ball point pen(space)

Re: White space in searches

Posted: Tue Jun 09, 2009 12:43 pm
by mikemike
Is this where your script posts to?

You need to find the variable that gets sent to the search page, which will be in $_GET or $_POST form. Normally $_GET if it's a search.

Let's say your search field is called 'search_str', then you simply do:

Code: Select all

$_GET['search_str'] = ' '.$_GET['search_str'].' ';
Put that at the top of the processing page, replacing the variable name for what it needs to be.

Re: White space in searches

Posted: Wed Jun 10, 2009 9:38 am
by bk1984
Thank you very much, I will give it a go now