一、练习建立get传值,建立模板list文件。
list.php代码:
<?php require './public/header.php'; $cate_id=intval(isset($_GET['cate_id'])?$_GET['cate_id']:''); foreach ($cates as $cate){ if ($cate['cate_id']==$cate_id){ echo '<h2>' . $cate['alias']. '</h2>'; break; } } echo '<ol>'; foreach ($movies as $movie){ if ($movie['cate_id']==$cate_id){ echo '<li>' . $movie['name'] . '</li>'; } } echo '</ol>'; require './public/dibu.php';
index.php代码:
<?php require './public/header.php'; foreach ($cates as $cate){ echo '<ol> <h2>' . $cate['alias'] . '</h2>'; foreach ($movies as $movie){ if ($movie['cate_id']==$cate['cate_id']){ echo '<li>' . $movie['name'] . '</li>'; } } echo '</ol>'; } require './public/dibu.php';
运行结果:
手抄作业: