【发布时间】:2015-12-25 06:20:06
【问题描述】:
我是 PHP 和 SQL 的新手。 我创建了一个显示 sql 数据库输出的 html 表。现在我想创建一个过滤器内容列,它允许用户根据通过过滤器表单提交的值过滤表内容。 这是代码
<div class="filter">
<label>Stream:</label>
<select name="stream" form="filtersubmit" required>
<option value="">Select</option>
<option value="AB">AB</option>
<option value="BC">BC</option>
<option value="CD">CD</option>
</select>
<label>College:</label>
<select name="college" form="filtersubmit">
<option value="">Select</option>
<option value="XY">XY</option>
<option value="YZ">YZ</option>
</select>
<form id="filtersubmit">
<input type="submit" value="Filter">
</form>
</div>
<div class="feed">
<?php
$conn4 = new mysqli("127.0.0.1", "root", "", "signup");
$hfeed = "SELECT id,college,stream ,price FROM items";
$resfeed = $conn4->query($hfeed);
echo "<table class='table table-hover'>";
echo "<thead><tr><th>College</th><th>Stream</th><th>Price</th></tr></thead>";
if ($resfeed->num_rows > 0) {
while ($row = $resfeed->fetch_assoc()) {
echo "<tbody><tr><td>" . $row["College"] . "</td><td>" . $row["stream"] . "</td><td>" . $row["price"] . "</td></tr></tbody>";
}
} else {
echo "No data found!";
}
echo "</table>";
我正在使用表单类型过滤器部分,这是正确的方法吗? 我应该使用什么,以便在选择过滤器时更新内容而无需重新加载页面。 我应该使用 JSon 和 AJAx 还是 Jquery 输出我的 sql 表。 我不知道 jquery,所以对一些代码的任何帮助都会很有用。
【问题讨论】: