【发布时间】:2021-02-17 03:38:21
【问题描述】:
在我提出这个问题之前,我用表格和表格搜索了其他类似的问题,但我没有找到解决方案。正如您从我的代码中看到的那样,我不知道为什么,但这不起作用..我有一个表格,里面有一个form method='post'..当我单击降序或升序按钮时,什么都没有发生,我没有知道为什么 ?有什么建议吗?
<form method="post">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th scope='col'>Id</th>
<th scope='col'>Name
<button class="btn btn-info btn-sm dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Sort by
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<button name="nameDescending" type="submit" class="dropdown-item btn btn-info">Descending</button>
<button name="nameAscending" type="submit" class="dropdown-item btn btn-info">Ascending</button>
</div>
</th><!-- ORDER BY "name" -->
<th scope='col'>Last</th><!-- ORDER BY "lastname" -->
<th scope='col'>Email</th><!-- ORDER BY "email" -->
<th scope='col'>Telephone</th><!-- ORDER BY "telephone" -->
</tr>
</thead>
<tbody>
<?php
if(isset($_POST['nameDescending'])){
$sql = "SELECT * FROM cust_information ORDER BY name DESC";
}
if(isset($_POST['nameAscending'])){
$sql .= "SELECT * FROM cust_information ORDER BY name ASC";
}
$result = mysqli_query($conn,$sql);
$rowCount = mysqli_num_rows($result);
if($rowCount > 0){
while($row = mysqli_fetch_assoc($result)){
echo "<tr>
<td scope='row'>{$row['auto_id']}</td> <!--difference between class='row' / scope='row'-->
<td>{$row['name']}</td>
<td>{$row['lastname']}</td>
<td>{$row['email']}</td>
<td>{$row['telephone']}</td>
</tr> ";
}
} else{
echo "<tr> <td colspan='5'>Nothing was found!</td> </tr> ";
}
?>
</tbody>
</table>
</form>
【问题讨论】:
-
对我来说工作正常,页面重新加载。小心你在表单中制作了另一个表单标签
-
<form>里面有一个<form> -
你是对的,我删除了第二个
form但仍然无法正常工作 -
大概是@ThunderBoy,这意味着您的一个或其他查询正在工作,否则您的行数不会为 ` > 0`。我有一种感觉,您的问题在于您检查是否,然后再检查一次 - 而不是 if/else。你做过调试吗?提交了哪些帖子值,正在生成哪个查询,准备执行查询时的 sql 字符串是什么............
标签: php html forms html-table