PDA

View Full Version : mySQL query 'like' problem


bazz
08-26-2007, 06:59 PM
Hi,

I am trying to match a field entry to four letters of a textbox (form) entry. It seesm only to work with the first four letters of the field value whereas I want to check the whole field 'string' for a potential match.

Any pointers on what I am missing?

The filed value is 'johny soap t/a metharg'
I want to match the 'harg' no matter whether it's at the beginning of the field value or the end.


my $shortenedGroup = substr($groupToAdd, 0,4);

print qq(shortenedGroup = $shortenedGroup<br />); # OUTPUTS (for example, 'harg')
my $dbh = DBI->connect("DBI:mysql:$db:$srv:$port", $user, $pass,
{RaiseError => 1, PrintError => 0})
or die "Can't connect: DBI->errstr()";

my $sth = $dbh->prepare("SELECT Business_Group_Name From $table
WHERE Business_Group_Name LIKE '${shortenedGroup}%' ");
$sth->execute;



As ever, your help and pointers will be appreciated


bazz

mcjwb
08-26-2007, 07:20 PM
I think you need a percentage sign before the value as well as after it.

bazz
08-26-2007, 08:17 PM
Excellent thanks. Seems now to work fine. :thumbsup:

bazz