Reputation: 159
Im going to make a search field, where the user types the item he/she is looking for.
lets say helm
in this example.
The database holds items, like:
id | name |
1 | helm of c
2 | helm of 9
3 | helm
4 | helmset
5 | helmapo
6 | haloween
how can i make the mysql query in this case return row 1-5, cause its all match?
Upvotes: 1
Views: 75
Reputation: 4079
You can use sql wildcards to handle this use case
SELECT row FROM tablename WHERE field LIKE '%helm%'
If you encapsulate the search term with % on both sides the SQL will return any row containing the search term at any index position, however if you only want return rows that start with helm then you would use the term
'helm%'
Upvotes: 1
Reputation: 403
You can use wildcards
SELECT * FROM table WHERE name LIKE '%helm%'
More information on wildcards: http://www.w3schools.com/sql/sql_wildcards.asp
Upvotes: 2
Reputation: 172428
You can try to make wildcard search like this:
select * from tablename where name like 'helm%'
Also if you the word helm
can appear in the middle of the column value or any place then put it like
select * from tablename where name like '%helm%'
Upvotes: 1