Page 1 of 1

Using the Select statement searching using a keyword

Posted: Thu Nov 13, 2008 5:45 am
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!

Re: Using the Select statement searching using a keyword

Posted: Thu Nov 13, 2008 5:53 am
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

Re: Using the Select statement searching using a keyword

Posted: Thu Nov 13, 2008 8:56 am
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?

Re: Using the Select statement searching using a keyword

Posted: Thu Nov 13, 2008 9:09 am
by swellular
SELECT * FROM tblname LIKE username='%$variable%';
Correct.