Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
-
deejay
- Forum Contributor
- Posts: 201
- Joined: Wed Jan 22, 2003 3:33 am
- Location: Cornwall
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?

-
jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
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
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.
-
deejay
- Forum Contributor
- Posts: 201
- Joined: Wed Jan 22, 2003 3:33 am
- Location: Cornwall
Post
by deejay »
cheers all
