这是我的表格和表格数据
表1
| id | name | age |
| 1 | rey | 13 |
| 2 | joel | 14 |
表2
| time id | id | minutes |
| 1 | 1 | 3 mins |
| 2 | 1 | 4 mins |
| 3 | 2 | 5 mins |
这是我的问题,如何在PHP代码中显示它?
view.php
NAME AGE
rey 13 [VIEW] (click view to transfer to other page)
joel 14 [VIEW] (click view to transfer to other page)
当我单击rey时,它将显示如下,依此类推,使用joel
other.php
MINUTES
3 mins
4 mins
答案 0 :(得分:1)
只需将相应的ID从第一页传递到第二页:
<强> view.php 强>
<?php
if(isset($_GET['id'])){
$link = mysqli_connect($host, $user, $password, $database) or die(mysqli_error($link));
$query = "SELECT * FROM table2 WHERE id = ".$_GET['id']." ORDER BY minutes";
$result = mysqli_query($link, $query) or die(mysqli_error($link));
if(mysqli_num_rows($result) > 0){
echo 'MINUTES<br>';
while ($row = mysqli_fetch_array($result, MYSQL_ASSOC)) {
echo $row['minutes'].'<br>';
}
}else{
echo 'No results found for given ID.';
}
}
?>
<强> other.php 强>
mysqli_connect()
不要忘记在 bb://link.fil?data=1
函数中添加适当的参数。
答案 1 :(得分:1)
在第一页中,所需表格上的正常select *
就足够了。这将为您提供所需的数据。
在第一个表格的view.php
页面上,相应地显示table1.name
和table1.age
。对于该链接,您可以使用server_url/other.php?id=<<id>>
的内容,其中<<id>>
是从初始table1.id
获得的相应select *
。
处理该页面的数据时,select * from table2 where id = <<id>>
就足够了;条件列表中的id
是绑定两个表的外键。