/    Sign up×
Community /Pin to ProfileBookmark

In String Search

I have a DB of names (100 – 1000s) and I want to cycle through each name and determine if the name is in the string I am searching. I have the names broken up into first and last and I thought about using a search for last names first and then doing first names, since last names are less common than first.

My first question is about efficiency. Is this an efficient way? If not what would be better.

My second question is once I get to the Smiths and Kims in the list of last names there will be times that it isn’t a match to the first name in the string. How can I pick back up in the DB search where I left off?

Thanks for the help

Seth

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMay 14.2009 — Perhaps just one query?
[code=php]
$name = mysql_real_escape_string($_POST['name_to_search_for']);
$query = "SELECT * FROM table WHERE last_name LIKE '%$name%' OR first_name LIKE '%$name%'";
[/code]
×

Success!

Help @Slickwilly9 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...