WHERE lower LIKE statement

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
deejay
Forum Contributor
Posts: 201
Joined: Wed Jan 22, 2003 3:33 am
Location: Cornwall

WHERE lower LIKE statement

Post by deejay »

Hi

Am puzzled as why this bit of code won't work for me.

Code: Select all

 
if (isset($_GET['wordsearch'])){
$word = strtolower($_GET['wordsearch']);
echo $word.'= $word <BR>';
$query .= " WHERE lower(lname) OR lower(fname)  LIKE'%$word%' ";
 
 
it works if use either

Code: Select all

$query .= " WHERE lower(lname)  LIKE'%$word%' ";
or

Code: Select all

$query .= " WHERE  lower(fname)  LIKE'%$word%' ";
but not when I add the OR statement it only gives me the result on what comes second in the statement. any ideas? :banghead:
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: WHERE lower LIKE statement

Post by jaoudestudios »

Your line 4 is wrong!

In line 5 you need a space after LIKE

You are using OR incorrectly.

It should be...

Code: Select all

$query .= " WHERE lower(lname) LIKE '%".$word."%' OR lower(fname) LIKE '%".$word."%'";
abhikerl
Forum Newbie
Posts: 9
Joined: Wed Jun 04, 2008 2:07 am
Location: Mauritius

Re: WHERE lower LIKE statement

Post by abhikerl »

For queries in sql, I suggest you to used sqlyog. It's a software that helps you to make queries, then you can copy, paste it in your code.
User avatar
deejay
Forum Contributor
Posts: 201
Joined: Wed Jan 22, 2003 3:33 am
Location: Cornwall

Re: WHERE lower LIKE statement

Post by deejay »

cheers all :)
Post Reply