【发布时间】:2020-01-13 04:19:03
【问题描述】:
我在下面更新了我的代码,我的 php 代码出现“500(内部服务器错误)”。
我对 PHP 和 jQuery、Ajax 还很陌生,而且我一直很难在 Internet 上找到一个可以帮助我解决问题的示例。任何人都可以向我解释我如何能够根据所选下拉列表的值将数据从数据库显示到 html TABLE 中,一种过滤器。
我已经设法从数据库中加载了所有数据并且可以正常工作,我尝试在网上寻找示例但找不到任何示例。
添加代码: HTML 代码:
<select name="countryN" id="countryCB">
<?php
while($rows = $resultSet->fetch_assoc())
{
$country = $rows['Country'];
echo "<option value='Test'>$country</option>";
}
?>
</select>
<input type="button" class="srchbtn" value="Seach">
</div>
</div>
<div class="item-container">
<div id="items">
<table id="brtable">
<thead>
<tr class="tblrow" id="headers">
<th>BR-Name</th>
<th>Country</th>
<th>Data Stream</th>
<th>Region</th>
<th>Actions to be taken</th>
</tr>
</thead>
<tbody id="tableresult">
</tbody>
</table>
</div>
</div>
PHP 代码:
<?php
$connect = mysqli_connect('127.0.0.1', 'root', '', 'testdb');
$countryN = $_POST['Country'];
$brfilterresult = ("SELECT Business_Rule_Name, Country, Data_Stream, Region,
ActionNeeded FROM businessrulestbl WHERE Country='".$countryN."'");
$result = $connect->query($brfilterresult);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row['Business_Rule_Name'] . "</td>";
echo "<td>" . $row['Country'] . "</td>";
echo "<td>" . $row['Data_Stream'] . "</td>";
echo "<td>" . $row['Region'] . "</td>";
echo "<td>" . $row['ActionNeeded'] . "</td></tr>";
}
}
?>
JS代码:
$(document).ready(function(){
$('#countryCB').change(function(){
var countryName = $(this).val();
$.ajax({
url:"../php/getbr.php",
method: "POST",
data: {countryName:countryName},
success: function(data){
$('#tableresult').html(data);
}
});
});
});
我只是希望有人向我解释如何以详细的方式实现我的目标,解释每个部分。一个示例源代码会很棒。
【问题讨论】: