How to retrieve data from mysql using drop down menu with text search field.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mmarif4u
    New Member
    • Sep 2006
    • 23

    #1

    How to retrieve data from mysql using drop down menu with text search field.

    Hi everyone,
    I have a little problem in php coding.
    i have mysql table guestbook:
    Fields are Id,name,email,c omment,datetime .
    Now i want to search the database by php query using
    a Dropdown menu (for example Name,Id) with a text search field.
    What will be the query.
    Can anyone help me with details.
    thanks.
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    May I conclude from your question ("What will be the query?") that you already have the drop-down and the textbox? If so, the table query can be defined as something like (search items in $search1 and $search2):
    Code:
    $sql  = 'SELECT Id, Name ';
            $sql .= 'FROM MyTable ';
            $sql .= 'WHERE Name REGEXP "' . $search1 . '" ';
            $sql .= 'AND Id REGEXP "' . $search2 . '" ';
            $sql .= 'ORDER BY Id';
    Ronald :cool:

    Comment

    • mmarif4u
      New Member
      • Sep 2006
      • 23

      #3
      Originally posted by ronverdonk
      May I conclude from your question ("What will be the query?") that you already have the drop-down and the textbox? If so, the table query can be defined as something like (search items in $search1 and $search2):
      Code:
      $sql  = 'SELECT Id, Name ';
              $sql .= 'FROM MyTable ';
              $sql .= 'WHERE Name REGEXP "' . $search1 . '" ';
              $sql .= 'AND Id REGEXP "' . $search2 . '" ';
              $sql .= 'ORDER BY Id';
      Ronald :cool:
      Thanks Ronald for reply.
      i dont have the complete code in php.
      Can u help me here in code.
      Thanks.

      Comment

      • rdub
        New Member
        • Oct 2006
        • 1

        #4
        Did you ever get the complete answer?

        Comment

        Working...