这是我的酒店流程 我想显示数据库中的数据,但有一些条件。比如价格。我想显示高于我们从表单函数提示的价格的数据。
<!DOCTYPE html>
<html>
<head>
<title>Hotel</title>
</head>
<body>
<?php
include 'dbh.php';
$price = $_POST['price'];
$query = "SELECT * FROM hotel";
$result = mysqli_query($conn, $query);
?>
<table id="Htable">
<tr class="header">
<th style ="width:60%;">Price</th>
<th style ="width:40%;">Hotel Name</th>
</tr>
<? while($rows = mysqli_fetch_array($result))
{
<? if($price > $rows['h_price'])
{ ?>
$h_price = $rows['h_price'];
$n_hotel = $rows['n_hotel'];
?>
<tr>
<td> <?= $h_price ?> </td>
<td> <?= $n_hotel ?> </td>
</tr>
<? } ?>
<? } ?>
</table>
</body>
</html>
这是我提示价格的表单页面 这个文件我想做表格为DSS做过滤系统。
<!DOCTYPE html>
<html>
<head>
PHP
</head>
<body>
<form action="hotelprocess.php" method="POST">
<p>
<label>Price:</label>
<input type="text" id="price" name="price" />
</p>
<p>
<input type="submit" name="hotel" />
</p>
</form>
</body>
</html>
这是数据库连接
<?php
//connect with database
$conn=mysqli_connect("localhost", "root", "", "register");
if(!$conn){
die("connection failed:".mysqli_connect_error());
}
?>
答案 0 :(得分:0)
通过sql语句检查价格条件。
<?php
include 'dbh.php';
if(isset($_POST['price'])){
$price = $_POST['price'];
$query = "SELECT * FROM hotel where h_price < '" .$price. "' ";
$result = mysqli_query($conn, $query);
}else{
$query = "SELECT * FROM hotel";
$result = mysqli_query($conn, $query);
}
?>
您可以显示这样的表格。
<?
while($rows = mysqli_fetch_array($result))
{
$h_price = $rows['h_price'];
$n_hotel = $rows['n_hotel'];
echo ' <tr>
<td> ='; echo $h_price; echo' </td>
<td> ='; echo $n_hotel; echo' </td>
</tr>';
}
?>