【发布时间】:2018-06-30 18:12:48
【问题描述】:
我创建了一个简单的搜索引擎,但我希望每当我搜索名称时它都会按原样显示在表格中。问题是其他数据只会隐藏,我不知道该怎么做。 这是我的 HTML 代码。
<form name="view" method="post" div class="frm1">
<table align="center" class="record_table" >
<tr bgcolor="#006600" height="50" style="color:#FFF;">
<th> </th>
<th>Name</th>
<th>Email</th>
<th>Packages</th>
<th>Contactno</th>
<th>Gender</th>
<th>File</th>
<th>Address</th>
<th>Action</th>
</tr>
Search:
<input type="text" size="20" name="search" onKeyup="srch();">
<div id="d1"</>
<script>
function srch()
{
xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","dbsearchfile.php?view="+document.view.search.value,false);
xmlhttp.send(null);
document.getElementById("d1").innerHTML=xmlhttp.responseText;
}
</script>
这是我的 PHP 代码。
<?php
$view=$_GET['view'];
mysql_connect("localhost","root","");
mysql_select_db("pm");
$res=mysql_query("select * from tblreservation where Name like ('$view%');");
echo "<table>";
while($row=mysql_fetch_array($res))
{
echo "<tr>";
echo "<td>";
echo "<div class=frm1>";
echo "<a href='#'>". $row['Name'] . "</a>";
echo "</td>";
echo "</tr>";
}
echo "</table>";
?>
【问题讨论】:
-
您的 HTML 有语法错误 (
<div id="d1"</>),您的 php 代码有语法错误,您容易受到 SQL 注入攻击,您的 ajax 代码不正确并且不等待来自的响应服务器等... -
“按原样显示在表格中”是什么意思?您是说要在不重新加载页面的情况下根据某些搜索过滤原始表格数据吗?
-
按名称实时搜索表行。
-
你错过了在
mysql_select_db("pm);中关闭"
标签: php jquery html-table