CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Mysql WHERE Parameters

Print topic Send  topic

Author Message
webtotaltoday

Posts: 46
Posted: 01/28/2008, 8:41 AM

Hi,

I have a simple search and results function, i cant seem to get the correct where parameter though. Say for instence it is searching on a field called producttitle, and in product title you have BMW M3 MIRRORS, i have tried contains like, in, equals, etc, and it works okay if you type in M3 MIRRORS, but if you type in BMW MIRRORS, it wont find it, can anyone help as to how i cant get this to work?

Same with if the product title is BMW BLACK M5 MIRRORS, if i type in black m5 it finds it, if i type in m5 mirrors it does also, but bmw m5 it doesnt and bmw mirrors it doesnt.

Can anyone help?

Thanks
View profile  Send private message
DonP
Posted: 01/28/2008, 9:35 AM

CodeCharge Studio creates keyPHRASE searches, not keyWORD so it will
find results only when they appear in the database as typed. To make it
work properly, you'll need some custom code to split it apart at the
spaces, then search on each word.

In a grid's Before Build Select event on your grid, try something like
this (you'll likely have to unwrap it to work properly):

global $KeyString;
global $tok;
global $size;
global $i;

if (CCGetParam("KeyString","")) {
$KeyString = str_replace(array("'","/","\"","of","The","the"), "",
trim(CCGetParam("KeyString","")));
$tok = split(" ", $KeyString);
$size = sizeof($tok);
for ($i = 0; $i< $size; $i++)
if (($i == 0) && ($i == $size-1)) {
$SearchResults->ds->Where .= " AND (productname LIKE
'%".$tok[$i]."%' OR productdescription LIKE '%".$tok[$i]."%' OR
productdnumber LIKE '%".$tok[$i]."%')" ;
} elseif ($i == 0) {
$SearchResults->ds->Where .= " AND ((productname LIKE
'%".$tok[$i]."%' OR productdescription LIKE '%".$tok[$i]."%' OR
productdnumber LIKE '%".$tok[$i]."%')";
} elseif ($i == $size-1) {
$SearchResults->ds->Where .= " AND (productname LIKE
'%".$tok[$i]."%' OR productdescription LIKE '%".$tok[$i]."%' OR
productdnumber LIKE '%".$tok[$i]."%'))";
} else {
$SearchResults->ds->Where .= " AND (productname LIKE
'%".$tok[$i]."%' OR productdescription LIKE '%".$tok[$i]."%' OR
productdnumber LIKE '%".$tok[$i]."%')";
}
}

Don (DonP)

webtotaltoday wrote:
> Hi,
>
> I have a simple search and results function, i cant seem to get the correct
> where parameter though. Say for instence it is searching on a field called
> producttitle, and in product title you have BMW M3 MIRRORS, i have tried
> contains like, in, equals, etc, and it works okay if you type in M3 MIRRORS, but
> if you type in BMW MIRRORS, it wont find it, can anyone help as to how i cant
> get this to work?
>
> Same with if the product title is BMW BLACK M5 MIRRORS, if i type in black m5
> it finds it, if i type in m5 mirrors it does also, but bmw m5 it doesnt and bmw
> mirrors it doesnt.
>
> Can anyone help?
>
> Thanks
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.yessoftware.com/
>
datadoit
Posted: 01/28/2008, 7:24 PM

Beautiful stuff DonP!
DonP
Posted: 01/28/2008, 11:52 PM

I wish I could claim credit but it was actually written for me years ago
by one of the nice CCS support staff. At the time I had barely started
with PHP and, of course, I've since modified it quite a bit.

Don (DonP)

webtotaltoday wrote:
> Hi,
>
> I have a simple search and results function, i cant seem to get the correct
> where parameter though. Say for instence it is searching on a field called
> producttitle, and in product title you have BMW M3 MIRRORS, i have tried
> contains like, in, equals, etc, and it works okay if you type in M3 MIRRORS, but
> if you type in BMW MIRRORS, it wont find it, can anyone help as to how i cant
> get this to work?
>
> Same with if the product title is BMW BLACK M5 MIRRORS, if i type in black m5
> it finds it, if i type in m5 mirrors it does also, but bmw m5 it doesnt and bmw
> mirrors it doesnt.
>
> Can anyone help?
>
> Thanks
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.yessoftware.com/
>

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.