要在网页上重新排列SQL查询结果,您可以使用以下方法:
例如,使用PHP和MySQL数据库:
0) {
while ($row = mysqli_fetch_assoc($result)) {
$data[] = $row;
}
}
// 关闭数据库连接
mysqli_close($conn);
// 在网页上显示查询结果
foreach ($data as $row) {
echo $row['column1'] . " - " . $row['column2'] . "
";
}
?>
例如,使用jQuery和PHP:
// 在按钮点击时触发事件
$("#your_button").click(function() {
// 发送AJAX请求到服务器获取数据
$.ajax({
url: "your_php_file.php",
type: "GET",
success: function(data) {
// 在网页上重新排列结果
data.forEach(function(row) {
$("#your_result_container").append(row.column1 + " - " + row.column2 + "
");
});
},
error: function() {
alert("请求失败");
}
});
});
在服务器端的PHP文件中,您可以编写与第1种方法相同的代码来执行SQL查询并返回结果。
无论您选择哪种方法,都需要根据您的具体需求和服务器环境进行调整。请确保在向网页上输出SQL查询结果时,采取适当的安全措施以防止SQL注入攻击。