带有位置下拉列表的搜索栏包含两个结果 - PHP / mySQL

Search Bar with Location dropdown sumit both results - PHP / mySQL

我有一个基本的搜索栏,可以使用关键字 (k) 搜索我的数据库。我正在尝试同时提交位置和搜索结果,但问题是当我提交搜索结果时,我得到的是 "search.php?k=builder&k=New+York" 而不是 "search.php?k=builder+New+York" 我该如何更正此问题?

HTML

<form action="search.php" method="get" style="margin:0 auto; text-align:center;">
    <input type="text" name="k" size="10" style="width:40%;"/>

    <div id="the-basics">
    <input class="typeahead" type="text" name="k" placeholder="States of USA">
        </div>

    <input type="submit" value="Search" style="width:100px;">
</form>

搜索栏PHP代码:

<?php
    if(!empty($_GET['k'])){
        //if search bar is empty
    }else{
       echo "'<meta http-equiv='refresh' content='0;url=index.php'>";
       //redirect back to index.php
    }
    $k = $_GET['k']; //k stands for keyword

    $i = 0;
    $terms = explode(" ", $k);
    $query ="SELECT * FROM record WHERE ";

    foreach ($terms as $each) {
        $i++;
        if ($i == 1)
            $query .= "company_name LIKE '%$each%' " . "OR website LIKE '%$each%' " . "OR email LIKE '%$each%' " . "OR tel LIKE '%$each%' " . "OR  description LIKE '%$each%'" . "OR  location LIKE '%$each%'" . "OR  description LIKE '%$each%'";

    }

    $connection = mysql_connect('localhost', 'username', 'password');
    mysql_select_db('DB_name');



    $query = mysql_query($query);
    $numrows = mysql_num_rows($query);
    if ($numrows > 0){

        while ($row = mysql_fetch_assoc($query)) { { ?>
        ..........search result shows here........

您好,您需要应用一些 JS

<script>
function submitForm(obj){
          var search =  $('input[name="k"]).val();
 var state=  $('#state').val();
 $('input[name="k"]).val(search+" "+state )
obj.submit();
}
</script>

<form action="search.php" method="get" style="margin:0 auto; text-align:center;" onsubmit=submitForm(this)>
    <input type="text" name="k" size="10" style="width:40%;"/>

    <div id="the-basics">
    <input class="typeahead" type="text" id="state" placeholder="States of USA">
        </div>

    <input type="submit" value="Search" style="width:100px;">
</form>