Developing a search field

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rachelle

    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!

  • windandwaves

    #2
    Re: Developing a search field

    Rachelle wrote:[color=blue]
    > 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![/color]

    we definitely need more information. What are the fields you are searching?
    what are people searching for?


    Comment

    • Pedro Graca

      #3
      Re: Developing a search field

      Rachelle wrote:[color=blue]
      > 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![/color]

      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


      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!

      Comment

      • bobzimuta

        #4
        Re: Developing a search field

        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.

        Comment

        Working...