php
  • database
  • html-table
  • 2016-02-27 75 views 0 likes 
    0

    這是我在我的房間如何將數據庫數據顯示到其他頁面?

    <?php 
        include'db.php'; 
        $sql=mysql_query("Select*from tb_rooms1"); 
        echo "<div class='container'>"; 
        echo "<div class='scrolltable'>"; 
        echo "<table class= 'table table-striped table-bordered'>"; 
        echo"<th><div align='center'>ID</div></th>"; 
        echo"<th><div align='center'>Image</div></th>"; 
        echo"<th><div align='center'>Room Name</div></th>"; 
        echo"<th><div align='center'>Description</div></th>"; 
        echo"<th><div align='center'>Price Per Night</div></th>"; 
        echo"<th><div align='center'>Status</div></th>"; 
        echo"<th><div align='center'>Reserve</div></th>"; 
    
        while($row=mysql_fetch_array($sql)) 
        { 
         @$id=$row['eid']; 
    
         echo"<tr align='center'>"; 
         echo"<td><div style='font-size:11px;' align='center'>".$row['roomID']</div></td>"; 
         echo"<td><div style='font-size:11px;' align='center'><img width=72 height=52 alt='Unable to View' src=".$row['image']."></div></td>"; 
         echo"<td><div style='font-size:11px;' align='center'>".$row['name']."</div></td>"; 
         echo"<td><div style='font-size:11px;' align='center'>".$row['description']."</div></td>"; 
         echo"<td><div style='font-size:11px;' align='center'>".$row['price']."</div></td>"; 
         echo"<td><div style='font-size:11px;' align='center'>".$row['status']."</div></td>"; 
         echo"<td><div align='center' style='margin-top:30px'><input style='margin-top:-2px;' type='checkbox'></div></td>"; 
        } 
        echo"</table>"; 
        echo"</div>"; 
        echo"</div>"; 
    ?> 
    

    我不知道我怎麼可以顯示我已經選擇了另一頁房間的信息表的代碼。有人能幫我嗎?我

    +1

    你需要更具體些,你是否想讓每個房間都可以點擊? – Addil

    回答

    0

    讓您的房間可點擊,並通過傳遞房間ID作爲參數

    echo"<td><div style='font-size:11px;' align='center'><a href='otherpage.php?roomid={$row['roomID']}'> Room {$row['roomID']}</a></div></td>"; 
    

    在你的其他PHP文件你會有這樣的事情:

    otherpage.php 
    <?php 
    include'db.php'; 
    $roomid = $_GET['roomid']; 
    $lookupQuery = mysqli_query("SELECT * FROM tb_rooms1 WHERE roomID = [$roomid]"); 
    

    ...顯示但你想要的數據

    你需要考慮的一件事情是mysql注入,因爲你的代碼是使用mysql並且參數被直接傳遞到你的查詢中...

    +0

    我想使用複選框。所以當我點擊並保留。它會顯示我選擇的房間的細節。你能幫我麼? – Kit

    相關問題