Search Field
21 posts by 3 authors in: Forums > CMS Builder
Last Post: July 6, 2011 (RSS)
By dccreatives - June 23, 2011
Can I have it search each word or ignore spaces?
Please advise.
Re: [dccreatives] Search Field
By Jason - June 23, 2011
On your search results page, you can use this to remove white spaces before you do your getRecords query:
// remove white space
if (@$_REQUEST['name_keyword']) {
$_REQUEST['name_keyword'] = str_replace(" ", "", $_REQUEST['name_keyword']);
}
Hope this helps
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Re: [Jason] Search Field
By dccreatives - June 27, 2011
I placed it in the header and I am still getting a record not found.
Attached is my header.
Re: [dccreatives] Search Field
By Jason - June 28, 2011
This code should go right before the getRecords() function at gets your search results. I took a look at your code and it looks like your form is submitting to "search.php", so your code would have to go there.
Hope this helps.
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Re: [Jason] Search Field
By dccreatives - June 28, 2011
One small issue left.
When I search Dia 1x1 or Dia 2x4 which are product names, I am not getting results.
When I search Dia without the sizing, I do get results. How can I get the results for the Dia 1x1,etc?
Re: [dccreatives] Search Field
By dccreatives - June 28, 2011
Same for Wet Beam4. If I search the whole word, I get no results. If I search wet, I get them.
Can't it search any of the words? or the entire word.
Re: [dccreatives] Search Field
By Jason - June 28, 2011
CMS Builder's automatic searching looks to see if the string appears somewhere in that field. It searches for the entire string, not each individual word.
To see what your query is actually searching for, you can add:
'debugSql' => true,
to your getRecords options. this will output the query that is being executed. You can then compare what is being searched for against the records you're expecting to see.
Hope this helps
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Re: [Jason] Search Field
By dccreatives - June 28, 2011
Re: [dccreatives] Search Field
By Jason - June 29, 2011
You can use the MYSQL function REPLACE to remove the white space from name field in the WHERE clause.
For example:
'where' => "REPLACE(name, ' ', '') LIKE '%".mysql_escape(@$_REQUEST['name_keywords'])."%'",
Hope this helps get you started.
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Re: [Jason] Search Field
By dccreatives - June 29, 2011
I put it on line 14
Instead of this:
list($itemsRecords, $itemsMetaData) = getRecords(array(
'tableName' => 'items',
'where' => whereRecordNumberInUrl(1),
'limit' => '45',
));
I put this, but it did not work, still giving me no results.
list($itemsRecords, $itemsMetaData) = getRecords(array(
'tableName' => 'items',
'where' => "REPLACE(name, ' ', '') LIKE '%".mysql_escape(@$_REQUEST['name_keywords'])."%'",
'limit' => '45',
));
I attached the php file.