database entries search

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • backups2007
    New Member
    • Jul 2007
    • 92

    database entries search

    I need help on database entry search.

    I am developing an inventory system. And I want a user to be able to search based on words/keywords that they will input in a textbox.

    Could anybody give suggestions? Thanks in advance.
  • nathj
    Recognized Expert Contributor
    • May 2007
    • 937

    #2
    Originally posted by backups2007
    I need help on database entry search.

    I am developing an inventory system. And I want a user to be able to search based on words/keywords that they will input in a textbox.

    Could anybody give suggestions? Thanks in advance.
    backups2007,

    The lowtech solution is to have a form which allows the user to search the inventory, post the information to a search results page. This page tests the information from the form and then, if it's good executes a search on the database displaying any selected results.

    The Form
    [html]
    <form id="searchForm " action="searchr esults.php" method="post">
    <input type="text" size="20" id ="searchText"na me="searchText "/>
    <input type="submit" id="SearchButto n" value="Search" />
    </form>
    [/html]

    The PHP
    [php]
    <?php
    // test the data
    if(!empty($_POS T['searchText']))
    {
    // search the database
    }
    [/php]

    This should give you a starting point, I do not know your data structure so you'll have to put in the SQL. But then it's a case of echoing out the results or displaying a message saying there are no matches.

    Cheers
    nathj

    Comment

    • ronverdonk
      Recognized Expert Specialist
      • Jul 2006
      • 4259

      #3
      Searching the database in a simple SQL stetement using regular expressions:
      [php]
      $sql = "SELECT * FROM table_name ".
      " WHERE field1 REGEXP '$search_word' ".
      " OR field2 REGEXP '$search_word' ".
      " OR field3 REGEXP '$search_word' ".
      " OR field5 REGEXP '$search_word' ".
      " ORDER BY field1 ";
      $result = mysql_query($sq l)
      or die("Error searching: ".mysql_error() );
      while ($wrn = mysql_fetch_arr ay($result) ) {
      // here display the results
      }
      [/php]
      Ronald

      Comment

      • backups2007
        New Member
        • Jul 2007
        • 92

        #4
        Originally posted by nathj
        backups2007,

        The lowtech solution is to have a form which allows the user to search the inventory, post the information to a search results page. This page tests the information from the form and then, if it's good executes a search on the database displaying any selected results.

        The Form
        [html]
        <form id="searchForm " action="searchr esults.php" method="post">
        <input type="text" size="20" id ="searchText"na me="searchText "/>
        <input type="submit" id="SearchButto n" value="Search" />
        </form>
        [/html]

        The PHP
        [php]
        <?php
        // test the data
        if(!empty($_POS T['searchText']))
        {
        // search the database
        }
        [/php]

        This should give you a starting point, I do not know your data structure so you'll have to put in the SQL. But then it's a case of echoing out the results or displaying a message saying there are no matches.

        Cheers
        nathj
        What if I put a dropdown box that may give a user an option which table to choose to search in. If for example, I have a user, product, and employee table.

        Could you give any suggestions with that? Thanks in advance...
        Last edited by backups2007; Oct 17 '07, 03:10 AM. Reason: incomplete post

        Comment

        • hawkenterprises
          New Member
          • Oct 2007
          • 10

          #5
          I would recommend a good full text search, doing a select on a inventory system will bog down your system fast.

          http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html

          Comment

          Working...