How do I search a table for all rows containing a phrase?

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
User avatar
mirra1515
Forum Commoner
Posts: 29
Joined: Fri Apr 25, 2008 3:17 am

How do I search a table for all rows containing a phrase?

Post by mirra1515 »

I am trying to figure out what mysql command would be necessary to search a table and return all rows that have a certain phrase in a column.

For instance, if my table was set up like this:

Database: test_db
Table: test_table
Columns: ID int(4), dataName varchar(255), dataContents text

How would I query the database so that it returns all rows in which "dataContents" contains a phrase such as "ipsum epsum". The phrase could be anywhere within the text field. For example:

"Indige huetoro ipsum epsum floro dolore"

Can I use LIKE? Or is there even a way to do this with mysql commands? Any suggestions would be greatly appreciated. Thank you :)
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: How do I search a table for all rows containing a phrase?

Post by Christopher »

SELECT * FROM test_table WHERE dataContents LIKE "%ipsum epsum%"
(#10850)
Post Reply