Product Search Codes
2 posts by 2 authors in: Forums > CMS Builder
Last Post: June 9, 2010 (RSS)
By paulmac - June 9, 2010
Hi
I want to search through a product code field I have in the database using a keyword search. The product codes are generaly made up of three blocks, something like - 'abcde 12345 fghij' with a space between each of the blocks.
Is there a way of searching that ignores the spaces, so if a user entered 'abcde12345fghij ' the correct product comes up even thoug the user has not included the spaces.
Thanks
I want to search through a product code field I have in the database using a keyword search. The product codes are generaly made up of three blocks, something like - 'abcde 12345 fghij' with a space between each of the blocks.
Is there a way of searching that ignores the spaces, so if a user entered 'abcde12345fghij ' the correct product comes up even thoug the user has not included the spaces.
Thanks
Re: [paulmac] Product Search Codes
By Jason - June 9, 2010
Hi,
The best thing to do is to strip out all of the spaces from what the user enters, and strip out all the spaces from the database value being searched against (don't worry, this doesn't permanently change the database value).
First, you need to capture what the client has entered and strip out the spaces. You would use something like this (NOTE:you'll have to change the names to match what you're using):
Next we need to use this value to search against our values in the database:
This will remove all the blank spaces from the value before performing the search.
Give this a try and let me know how it works for you. If you run into any issues, let me know and attach the .php file you're working with.
Thanks.
The best thing to do is to strip out all of the spaces from what the user enters, and strip out all the spaces from the database value being searched against (don't worry, this doesn't permanently change the database value).
First, you need to capture what the client has entered and strip out the spaces. You would use something like this (NOTE:you'll have to change the names to match what you're using):
$productName=str_replace(" ","",@$_REQUEST['productName']);
Next we need to use this value to search against our values in the database:
list($productRecords,$productMetaData)=getRecords(array(
'tableName'=>'products',
'where' => "replace(product_name,\" \",\"\")='".mysql_escape($productName)."'",
'allowSearch => false,
));
This will remove all the blank spaces from the value before performing the search.
Give this a try and let me know how it works for you. If you run into any issues, let me know and attach the .php file you're working with.
Thanks.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/