如何将数据库数据显示到另一个页面?

时间:2016-02-27 11:34:17

标签: php database html-table

这是我的房间表的代码

<?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 个答案:

答案 0 :(得分: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,参数直接传递给你的查询......

相关问题