PHP Two Search boxes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jamesmoore
    New Member
    • Jan 2011
    • 47

    #1

    PHP Two Search boxes

    Hi

    I have two search boxes with one submit button

    I want one search box to search one table in my database and the other search box to search another table in my database

    Then If there is a match between the two I want the results to be displayed

    THANKS!

    James

    Code:
    <form action="today.php" method="post">
    <input type="text" name="search">
    <input type="text" name="search2">
    <input type="submit">
    </form>
    <hr width="100%"></hr>
    
    <?php
    if(strlen(trim($_POST['search'])) > 0) {
    //all of your php code for the search
    
       $search = "%" . $_POST["search"] . "%";
    
     
      mysql_connect ("", "", "");
      mysql_select_db ("");
     if (!empty($_POST["search_string"])) 
       { 
    
       }  
      $query = "SELECT title,location,msg FROM job_tit,job_loc WHERE (job_title.msg_id=job_loc.msg_id)"; 
    
    
      $result = mysql_query ($query);
      if ($result) {
        while ($row = mysql_fetch_array ($result)) {
          echo "<br>$row[0]<br/>";
          echo $row[1];
          echo "<br>$row[2]<br/><br><br/>";
          
        }
      }
    }
    ?>
    </body>
    </html>
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    What do you mean by match between the two?

    For exmaple:

    foo = is search term 1
    bar = is search term 2

    You have two tables: tA and tB.

    You have 4 possible outcomes:

    foo is found only in tA
    bar is found only in tB
    foo is found in tA and bar is found in tB
    Neither foo nor bar are found in their respective tables.

    Is the data found in the two tables related? Do they have common info, i.e. same fields?


    Dan

    Comment

    Working...