PDA

View Full Version : Doing a keyword search with MySQL database query



redsox9
06-03-2007, 08:19 PM
Okay, here's what I want to do: I have a MySQL database with a text field that I've labeled keywords. What I want to be able to do is a search within that field for a particular value like home run or David Ortiz. So, I did a little research to see how I might do this and the closest that I came to finding an answer looks like this:


$kw = $_GET['keyword'];
$query = "SELECT * FROM table1 t1 WHERE t1.keywords LIKE '$kw'";

As you might have guessed, it doesn't return beans. I also tried:


$query = "SELECT * FROM table1 t1 WHERE '$kw' IN(t1.keywords)";

This also did not return any results. Any thoughts? :confused:

areidmtm
06-03-2007, 09:38 PM
Try


$query = "SELECT * FROM table1 t1 WHERE t1.keywords LIKE '%$kw%'";

redsox9
06-04-2007, 04:52 AM
That worked like a charm!

*bows in direction of areidmtm*