嘿伙计们,所以我使用php ajax进行实时搜索,但我每行数据都会得到一个表格,我如何制作它以便所有行都在同一个表格中?这是home.php
function showUser() {
var subject = document.getElementById("subject").value;
var equipmentname = document.getElementById("equipmentname").value;
if (subject == "" && equipmentname == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
// code for IE6, IE5
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("txtHint").innerHTML = this.responseText;
}
};
xmlhttp.open("GET","getsubject.php?subject="+subject+"&equipmentname="+equipmentname,true);
xmlhttp.send();
}
}
</script>
<form style="margin-left:30%">
<select style="height:26px" name="subject" id="subject" onchange="showUser()">
<option value="">Select Subject:</option>
<option value="Physics">Physics</option>
<option value="Chemistry">Chemistry</option>
</select>
<input type="text" name="equipmentname" id="equipmentname" onkeyup="showUser()">
</form>
<br>
<div id="txtHint">
这是getsubject.php`
<?php
$subject = strval($_GET['subject']);
$itemname = strval ($_GET['itemname']);
include "connect.php";
$i="SELECT * FROM inventory WHERE ('$subject' = '' OR subject='".$subject."') AND ('$itemname' = '' OR equipmentname = '".$itemname."') ";
$h = mysql_query($i);
while($tr = mysql_fetch_array($h)) {
?>
<center>
<table style="width:20%" class="table table-bordered table-striped">
<tr>
<td><?php echo $tr[0];?></td>
<td><?php echo $tr[1];?></td>
<td><?php echo $tr[2];?></td>
</tr>
</table>
</center>
<?php
}
?>
</body>
`
感谢