1

Hm, I think this will be an easy question but I can't find an answer to it.

I have a column called "name" in a mysql table.

A input might look like "How to programme 13".

I select it like this:

"SELECT * FROM lists WHERE name LIKE '%to programme 13%'"

This returns the row. But I want to be able to search for "how programme" or "how to 13". How can I search for this and make it return a result?

Thanks

Edit:

So basically I have to split the search string variable before searching? I have a search string

$sw = $_GET['sw'];
"SELECT * FROM lists WHERE name LIKE '%".$sw."%'"
Harpo
  • 83
  • 4

4 Answers4

2
SELECT * FROM lists WHERE name LIKE '%programme%' AND name LIKE '%how%' 

you can use REGEXP

 SELECT * FROM lists WHERE name REGEXP 'programme.+how'

Here you have a similar question: MySQL SELECT LIKE or REGEXP to match multiple words in one record

Community
  • 1
  • 1
Jorgesys
  • 124,308
  • 23
  • 334
  • 268
1
 SELECT * from lists where name REGEXP 'how|program|13'
Alireza Fallah
  • 4,609
  • 3
  • 31
  • 57
bart2puck
  • 2,432
  • 3
  • 27
  • 53
0

simple repeat condition with OR

SELECT * FROM lists 
WHERE name LIKE '%how programme%'
  OR  name LIKE '%how to 13%'
Siddique Mahsud
  • 1,453
  • 11
  • 21
-1

This query, searches for rows that have programme AND how

SELECT * FROM lists WHERE name LIKE '%programme%' AND name LIKE '%how%'
Alireza Fallah
  • 4,609
  • 3
  • 31
  • 57