470,815 Members | 1,103 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,815 developers. It's quick & easy.

Developing a search field

I'm developing a webpage interface for the employees I work with that
will allow them to search the database for things. I have everything
else set up, but i'm having problems actually developing the search
script.... basically my select statement. Anyone with examples of how
to do this would be appreciated. Thanks!

Jan 11 '06 #1
3 1121
Rachelle wrote:
I'm developing a webpage interface for the employees I work with that
will allow them to search the database for things. I have everything
else set up, but i'm having problems actually developing the search
script.... basically my select statement. Anyone with examples of how
to do this would be appreciated. Thanks!


we definitely need more information. What are the fields you are searching?
what are people searching for?
Jan 11 '06 #2
Rachelle wrote:
I'm developing a webpage interface for the employees I work with that
will allow them to search the database for things. I have everything
else set up, but i'm having problems actually developing the search
script.... basically my select statement. Anyone with examples of how
to do this would be appreciated. Thanks!


I use something a lot like this when searching for data in several
different database columns:

<?php
$sql = "select name, city, age from people where 1=1";
if (isset($_POST['has_name'])) $sql .= " and name='{$_POST['name']}'";
if (isset($_POST['has_city'])) $sql .= " and city='{$_POST['city']}'";
if (isset($_POST['has_age'])) $sql .= " and age='{$_POST['age']}'";
?>

If you want to search text within specific columns
try using Full-Text Search functions
http://dev.mysql.com/doc/refman/5.1/...xt-search.html

Maybe you'd like to post to comp.databases.mysql for a more
comprehensive answer (mine is [slightly] off topic here).

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Jan 11 '06 #3
Also check out soundex() in mysql documentation.

In a query : SELECT first_name FROM people WHERE soundex( first_name )
= soundex( 'mark' )

will return something like the following
marcus
marko
.... (more)

Don't forget your 'like' queries as well...
SELECT first_name FROM people WHERE first_name LIKE 'mar%'

will return everything starting with 'mar'

You can also wrap strings for LIKE using '%string%' and '%string'

If you're interested in performance, text searching does take a bit of
computing power, so take that into consideration.

Jan 12 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.