实例 详情页
<?php $xq=[ ['id'=>01,'con'=>'我是一个苹果,我很甜'], ['id'=>02,'con'=>'我是一个香蕉,我很香'], ['id'=>03,'con'=>'我是一个橘子,我很算'], ]; $id = intval($_GET['id']); foreach ($xq as $qq) { if($id===$qq['id']){ echo $qq['con']; } }
运行实例 »
点击 "运行实例" 按钮查看在线实例
实例 列表页
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>列表页</title> </head> <body> <?php $list=[ ['id'=>01,'name'=>'苹果','dj'=>2.1,], ['id'=>02,'name'=>'香蕉','dj'=>3.3,], ['id'=>03,'name'=>'橘子','dj'=>5.2,], ]; ?> <div style="width: 500px;"> <table style="color: blue;width:500px;border: 1px solid lightslategray;text-align:center;height: 100px;"> <caption style="font-size: 30px;color:red;text-align: center;">商品名单</caption> <thead> <tr> <th>序号</th> <th>名称</th> <th>单价</th> <th>详情</th> </tr> </thead> <tbody> <?php foreach ($list as $lis):?> <tr style='border: 1px solid red;'> <?php foreach ($lis as $td): ?> <?php echo "<td style='border: 1px solid red;'>$td</td>"; ?> <?php endforeach;?> <!-- 重点: 三行循环完了在最后追加一行详情链接--> <?php echo "<td style='border: 1px solid red;'><a href='xq.php?id={$lis['id']}'>详情</a></td>"; ?> </tr> <?php endforeach;?> </tbody> </table> </div> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例