1,105,578 Community Members

Search query

Member Avatar
davy_yg
Veteran Poster
1,117 posts since May 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 1 [?]
 
0
 

Hallo,

I am trying to fix my mysql search query:

 $data = mysql_query("SELECT * FROM static_content WHERE upper(image) or upper(title) or upper(content) LIKE'%$find%'"); 

Please help me to fix it. Is it correct?

I mean where column image (change to upper case) or column title (change to upper case) or column content (change to upper case) like the data that I input in the search box (the code before it already change it to uppercase).

Member Avatar
pritaeas
mod_pritaeas
11,312 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,835 [?]
Skill Endorsements: 155 [?]
Moderator
Featured
Sponsor
 
0
 

No, it's not correct. You need LIKE after every column, unless you concatenate them first.

Member Avatar
davy_yg
Veteran Poster
1,117 posts since May 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 1 [?]
 
0
 

How to concatenate them ? like where ?

Member Avatar
pritaeas
mod_pritaeas
11,312 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,835 [?]
Skill Endorsements: 155 [?]
Moderator
Featured
Sponsor
 
0
 
Member Avatar
davy_yg
Veteran Poster
1,117 posts since May 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 1 [?]
 
0
 

I read the guide, I still do not understand how to apply it to my query. I guess I just use this one:

 $data = mysql_query("SELECT * FROM static_content WHERE upper(image) LIKE'%$find%' or upper(title) LIKE'%$find%' or upper(content) LIKE'%$find%'"); 

Is that correct?

Member Avatar
pritaeas
mod_pritaeas
11,312 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,835 [?]
Skill Endorsements: 155 [?]
Moderator
Featured
Sponsor
 
0
 

Is that correct?

Yes.

Apart from that. In most cases comparisons in queries are case-insensitive, so you could probably do without UPPER()

Member Avatar
davy_yg
Veteran Poster
1,117 posts since May 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 1 [?]
 
0
 

Thanks. I probably will close this forum.

If anyone can help me with this one would great:

another related thread

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article