Nov 04
Jim Sheffer [OTish]Building a MySQL Like statement into a variable
Nov 04, 2013; 18:13
Jim Sheffer
[OTish]Building a MySQL Like statement into a variable
Hello all-
First off: Lasso 8.6
I have the following code building a search variable for a product search using MySQL. The variable =93keyword=94 may contain multiple search terms - In this example I=92m using:
losi red mini (could be in any order):
var(
=91keyword=92 = action_param(=91keyword=92),
'sqlSearch') = string;
var('temp_key') = string_findregexp(($keyword),-find='\\w*');
loop($temp_key->size);
var('temp') = $temp_key->get(loop_count);
$sqlSearch += 'product_name LIKE \'%' + $temp + '%\' AND ';
/loop;
$sqlSearch->removetrailing('AND ');
THIS:
SELECT product_id, product_name FROM products WHERE "' + $sqlSearch + =91"
PRODUCES THIS:
action_statement: SELECT product_id, product_name, product_desc FROM products WHERE product_name LIKE '%losi%' AND product_name LIKE '%red%' AND product_name LIKE '%mini%'
Which works (any comments on doing this more efficiently are always welcome)!
Ultimately,however, I need to search 3 different fields with this information and would like the results to be in order so that anything matching on the product_id field would be listed as the results first (higher relevance), then product_name, then product_desc. I don=92t know if I need to run 3 separate searches or can combine this into one search
I need to search 3 fields:
product_id
product_name
product_desc
Any ideas on the best way to accomplish this?
Also, I want to remove common words from the $keyword, such as =93the, or, and, etc=85
Some of the search words will contain only 3 letters and will be valid, so I can=92t remove based on size.
Is there a better way than doing something like this?
($keyword->replace(=91and ', ''));
($keyword->replace(=91or', ''));
($keyword->replace(=92the', ''));
etc=85
Thanks for taking a look!
James
James Sheffer jim@higherpowered.com
Lasso Developer http://www.higherpowered.com
phone: 469-256-0268
#############################################################
This message is sent to you because you are subscribed to
the mailing list Lasso
Lasso@lists.lassosoft.com
To unsubscribe, E-mail to: <Lasso-unsubscribe@lists.lassosoft.com>
Send administrative queries to <Lasso-request@lists.lassosoft.com>
Nov 04
Steve Piercy - Web Site Builder Re: [OTish]Building a MySQL Like statement into a variable
Nov 04, 2013; 16:28
Steve Piercy - Web Site Builder
Re: [OTish]Building a MySQL Like statement into a variable
Nov 04
Jim Sheffer Re: [OTish]Building a MySQL Like statement into a variable
Nov 04, 2013; 18:41
Jim Sheffer
Re: [OTish]Building a MySQL Like statement into a variable
Nov 05
jolle Re: [OTish]Building a MySQL Like statement into a variable
Nov 05, 2013; 08:20
jolle
Re: [OTish]Building a MySQL Like statement into a variable
Nov 05
jolle Re: [OTish]Building a MySQL Like statement into a variable
Nov 05, 2013; 08:36
jolle
Re: [OTish]Building a MySQL Like statement into a variable
Nov 05
Bil Corry Re: [OTish]Building a MySQL Like statement into a variable
Nov 05, 2013; 13:02
Bil Corry
Re: [OTish]Building a MySQL Like statement into a variable
Nov 05
Jim Sheffer Re: [OTish]Building a MySQL Like statement into a variable
Nov 05, 2013; 09:55
Jim Sheffer
Re: [OTish]Building a MySQL Like statement into a variable
Nov 05
jolle Re: [OTish]Building a MySQL Like statement into a variable
Nov 05, 2013; 17:23
jolle
Re: [OTish]Building a MySQL Like statement into a variable
Nov 05
Trevor Borgmeier Re: [OTish]Building a MySQL Like statement into a variable
Nov 05, 2013; 10:30
Trevor Borgmeier
Re: [OTish]Building a MySQL Like statement into a variable
Nov 05
Jim Sheffer Re: [OTish]Building a MySQL Like statement into a variable
Nov 05, 2013; 10:39
Jim Sheffer
Re: [OTish]Building a MySQL Like statement into a variable