Search database for part of a text input

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Tehquickness
Forum Commoner
Posts: 32
Joined: Mon Oct 24, 2005 11:31 pm

Search database for part of a text input

Post by Tehquickness »

Lets say i had a database of member information and I wanted to search the name field for 'Ryan' to find all the Ryans regardless of the last name.
what would be the mysql query to do that with?
I was thinking it would be

Code: Select all

SELECT * FROM members_page WHERE name = 'ryan *';
or something close but no combination of that i have tried seems to work for me.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Code: Select all

SELECT * FROM members_page WHERE name like 'ryan%'
Tehquickness
Forum Commoner
Posts: 32
Joined: Mon Oct 24, 2005 11:31 pm

Post by Tehquickness »

awesome that works perfectly. Am i correct to assume that the % is a wildcard? and if that is the case i could also use it like %word% to search for something with text on both sides
EX

%gath%

would find

Ryan Gathmann
and
Ryan gathster
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Very true indeed :)

You could always try it ;)
Post Reply