Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/422.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php和javascript搜索MYSQL并在同一html表中显示结果_Javascript_Php_Jquery_Html_Mysql - Fatal编程技术网

使用php和javascript搜索MYSQL并在同一html表中显示结果

使用php和javascript搜索MYSQL并在同一html表中显示结果,javascript,php,jquery,html,mysql,Javascript,Php,Jquery,Html,Mysql,我有一个下拉列表如果在下拉列表中选择的值在html表中显示关于在下拉列表中选择的值的数据,我有搜索框现在搜索工作正常它显示结果而不刷新页面,问题是现在它在同一页面上显示下拉html表和搜索值结果,但是我想在同一个html表上显示搜索结果,请参见下面的代码,有人可以指导我这样做吗?谢谢 <html> <select name="client" id="client" style="margin:-8px 0 0 1px;background-color:#E8E8E8;widt

我有一个下拉列表如果在下拉列表中选择的值在html表中显示关于在下拉列表中选择的值的数据,我有搜索框现在搜索工作正常它显示结果而不刷新页面,问题是现在它在同一页面上显示下拉html表和搜索值结果,但是我想在同一个html表上显示搜索结果,请参见下面的代码,有人可以指导我这样做吗?谢谢

<html>

<select name="client" id="client" style="margin:-8px 0 0 1px;background-color:#E8E8E8;width:104px;position: absolute;"> 
<option value="">Select Client</option>
<?php
i am connection to mysql
$sql=mysql_query("xxxxxxxxxx");
$clientid=$_GET['clientid'];
while($row=mysql_fetch_assoc($sql))
{
if(strlen($_GET['clientid'])>0 && $_GET['clientid']==$row['clientid'])
{
print' <option id="client" name="client" value="'.$row['clientid'].'">'.$row['clientid'].' </option>';
}
else{
print' <option id="client" name="client" value="'.$row['clientid'].'">'.$row['clientid'].' </option>';
}
}
?>
</select>

     <form id="lets_search" action="" style="width:0px;margin:-27px 0 0;text-align:left;">
                   <input type="text" name="region" id="region"> 
                   <input type="text" name="country" id="country">
                   <input type="submit" value="search" name="search" id="search">
          </form>

     <div id="content"></div>

    <table id="CPH_GridView1"  >
    <thead class="fixedHeader">
    <tr>
    <th style=" width:103px">Region  </th>
    <th style=" width:102px" >Country </th>

    <tbody id="fbody" class="fbody" style="width:1660px" >
    <div id="content">
    <?php
    $client_id  = $_POST['title'];
    if($client_id!=""){
    $sql_selectsupplier  = "xxxxxxxxxxx";
    echo '   <td style="width:103px" class=" '.$rows["net_id"].'">'.$rows["clientid"].'</td>
             <td style="width:102px" id="CPH_GridView1_clientid" class=" '.$rows["net_id"].'">'.$rows["region"].'</td>';

    </div>
    </tbody>
    </table>

    </html>

//javascript on the same page

<script type="text/javascript">
      $(function() {
        $("#lets_search").bind('submit',function() {
         var valueregion = $('#region').val();
          var valuecountry = $('#country').val();
          $.post('clientnetworkpricelist/testdb_query.php',{valueregion:valueregion,valuecountry:valuecountry}, function(data){
             $("#content").html(data);
           });
           return false;
        });
      });
    </script>

选择客户端
区域
国家

好的,我发现您的HTML代码有两个问题。一是使用两个ID相同的html元素(“内容”),这不是ID的目的。第二,将div放在tbody中不是有效的html

根据您的解释,我知道您试图在一个表中显示这两个操作的结果。 所以,删除第一个div

    <div id="content"></div>

此外,还可以删除tbody中的div。

要获得最佳实践,请将php代码与html分开-在呈现html之前,从数组中的db中获取所有数据,并在html中使用foreach解析每一行的afetr

将DB登录和连接放在不同的RNET文件中,并在页面顶部使用require_once()将其插入

显示错误以更好地理解脚本

ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
注释“我正在连接mysql”这行,因为它将导致此格式的错误

连接到数据库后初始化

$sql_search = ""; // otehrwise it will bring a notice when calling "$sql_search.="
并检查http_请求,以便在没有$_POST数据的情况下首次访问页面时不会带来任何错误

if ( $_SERVER['REQUEST_METHOD'] === 'POST')
{
   //code for displaying the new table with the post data
}
$sql_search = ""; // otehrwise it will bring a notice when calling "$sql_search.="
if ( $_SERVER['REQUEST_METHOD'] === 'POST')
{
   //code for displaying the new table with the post data
}