Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is wrong with this search query?? (Unknown column error)

Status
Not open for further replies.

TheDust

Programmer
Aug 12, 2002
217
US
I've been trying to use the following query to run a search through php onto my MYSQL database:

($srch is put together as "%".$searchText."%" to look for the text anywhere within the values)

---------
"SELECT * FROM a_artists, a_albums, a_labels WHERE a_artists.artistID = a_albums.artistID AND a_albums.labelID = a_labels.labelID AND ((a_artists.artistName LIKE `$srch`) || (a_albums.albumTitle LIKE `$srch`)) ORDER BY albumTitle"
---------

Again, "$srch" is what the user has typed in the search box, with a "%" on each side. I get the following error:

---------
Unknown column '%Blue Dog%' in 'where clause'
---------

"Blue Dog" is what the user typed in the first place. It is not understanding that I'm trying to look for a substring here. Can anyone help me out here??

 
Change the ` to a ' or a ". Text encapsulated in `s means a table/column/database in MySQL. //Daniel
 
Wow, how did I let that slide?? Arrghh... I need sleep... Thanks a lot man, just needed a pair of outside eyes to check it out, I guess.
 
Actually I have one more question about using '%' in MYSQL. How come this returns results...

SELECT * FROM a_artists WHERE artistName = 'no doubt';

... and this doesn't..?

SELECT * FROM a_artists WHERE artistName = 'no doubt';
(note: I just added the '%' signs)

What gives?
 
equality (=) returns that exact string, even if it contains wildcards

pattern matching (LIKE) uses the wildcards to determine where the pattern is that it's trying to match

make sense?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top