2017-04-20 29 views
0

這是我的酒店進程 我想顯示數據庫中的某些條件的數據。例如價格。我想顯示的數據高於我們從表單函數提示的價格。我不知道如何解決我的PHP和PHPmyAdmin中的錯誤

<!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']; \t 
 
      ?> 
 
      <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()); 
 
} 
 

 
?>

+1

您是否試過僅查詢那些適合您的酒店?像'選擇*從酒店的價格= $價格;'。當然使用>或<而不是=。 – Hienz

+2

這是一團糟。我在代碼中看到許多拼寫錯誤,包括在PHP標記之外使用<?'開始標記和PHP變量。在尋求幫助之前解決您的基本語法錯誤。 – miken32

+0

沒有任何錯誤,我們不能幫助你,因爲@ miken32說你的代碼是一團糟,你有其他PHP開放/關閉標籤內的PHP打開/關閉標籤。 –

回答

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>'; 

    } 

?> 
相關問題