Using the Select statement searching using a keyword

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
oscardog
Forum Contributor
Posts: 245
Joined: Thu Oct 23, 2008 4:43 pm

Using the Select statement searching using a keyword

Post by oscardog »

Couldn't think of a decent title, was hard to explain but i want to do it so that a person using the website can input something into a form and then it brings back multiple results(possibly)

So say in my database, i have 5 entries and they are "Black Sheep, White Sheep, Yellow Sheep, Black Bird and Human" (Random examples)

and someone inputs "Sheep" into the text field in the form. I want it to search the database using the keyword "Sheep" so it would bring up the first 3 entries i mentioned above. If they were to enter "Black" it would bring up "Black Sheep" and "Black Bird"

I don't need a full script with how to show the data, just how to search the database using that keyword and then i guess you'd use a while look to show the data :)

THanks!
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: Using the Select statement searching using a keyword

Post by novice4eva »

I just learned from the forum that mysql doesn't do case sensitive like searches so i know this would be the SQL
"SELECT * FROM table WHERE tableColumnName LIKE '%BLACK%'"
But oracle checks the case too
oscardog
Forum Contributor
Posts: 245
Joined: Thu Oct 23, 2008 4:43 pm

Re: Using the Select statement searching using a keyword

Post by oscardog »

So if i wanted to use a keyword taken from a form i would use that something like:

SELECT * FROM tblname LIKE username='%$variable%';

Or would there be no need for the percentages if im using a variable?
swellular
Forum Newbie
Posts: 3
Joined: Thu Nov 13, 2008 9:05 am

Re: Using the Select statement searching using a keyword

Post by swellular »

SELECT * FROM tblname LIKE username='%$variable%';
Correct.
Post Reply