Reputation: 35
I'm working on a PHP/MySQL app and I'm trying to match text to one of two fields.
My database has primaryname
and alternatename
: primaryname
is a single word of text. alternatename
is a comma separated list.
It works for matching primary name, but the OR part is causing the entire query to fail.
Working part:
$sql_statement = "SELECT primaryname, alternatename, notes, imageurl, status ";
$sql_statement .= "FROM fish ";
$sql_statement .= "WHERE primaryname LIKE '".$fishname."'";
Here's what I have (not working):
$sql_statement = "SELECT primaryname, alternatename, notes, imageurl, status ";
$sql_statement .= "FROM fish ";
$sql_statement .= "WHERE primaryname LIKE '".$fishname."' OR alternatename LIKE %'".$fishname."'%";
Any ideas? Thanks!
(P.S. Sorry if the formatting didn't work right. This is my first question on Stack Overflow after lurking for many years. Couldn't find an answer to this one.)
Upvotes: 1
Views: 79
Reputation: 197
I'd leave this in a comment but reputation not high enough.
It looks like you % signs shoud be in the single quotes '%".$fishname."%'
Upvotes: 1