你能帮助我如何从MySQL表中排序数据吗?使用php对mysql表中的数据进行排序
我想排序是通过表头:
<?php
if(isset($_POST['search'])) {
$valueTosearch = $_POST['searchvalue'];
$query = "SELECT * FROM `admin` WHERE CONCAT(`id`, `name`, `gender`, `user_group`, `date_registered`) LIKE '%".$valueTosearch."%'";
$search_result = filterTable($query);
} else {
$query = "SELECT * FROM `admin`";
$search_result = filterTable($query);
}
function filterTable($query)
{
include('config/dbconnect.php');
$filter_result = mysqli_query($con, $query);
return $filter_result;
}
?>
<form method='post' action=''>
<div><input type = 'text' name = 'searchvalue' placeholder="search by name">
<span>
<div style='margin-bottom:3px; margin-top:3px'>
<input id='gradient' class='search-btn' type = 'hidden' name = 'search' value = 'search'>
</div>
</span>
<div style="height: auto">
<table id='responsive_table'>
<thead>
<tr>
<th scope="col"><a href="sort">name</a></th>
<th scope="col"><a href="sort">sex</a></th>
<th scope="col"><a href="sort">user group</a></th>
<th scope="col"><a href="sort">date register</a></th>
</tr>
</thead>
<?php while($row = mysqli_fetch_array($search_result)): ?>
<tbody>
<tr>
<td scope="row" data-label='name'><?php echo $row['name']; ?></td>
<td data-label='sex'><?php echo $row['gender']; ?></td>
<td data-label='user group'><?php echo $row['user_group']; ?></td>
<td data-label='date register'><?php echo $row['date_registered']; ?></td>
</tr>
</tbody>
<?php endwhile; ?>
</table>
</div>
</form>
你的意思是,你正在寻找的东西是这样的:https://datatables.net/examples/styling/bootstrap .html? – Twinfriends
你可以使用JQuery吗? – Alessandro
究竟@Twinfriends – Ryan