Blogger Information
Blog 13
fans 0
comment 0
visits 6959
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php-首頁,列表頁,詳細頁(2019年7月24日)
Little的博客
Original
587 people have browsed it

实例

<?php
// header
include __DIR__ . "/component/header.php";

//build html template by php
echo '<ol>';
foreach ( $cates as $cate ):
	// echo title
	echo '<h2>' . $cate['name'] . '</h2>';

	//echo list
	foreach ( $foods as $food ):
		//find same id
		if ( $cate['cate_id'] === $food['cate_id'] ) {
			echo '<li><a href="detail.php?foods_id=' . $food['foods_id'] . '">' . $food['name'] . '</a></li>';
		}

	endforeach;
endforeach;
echo '</ol>';

// footer
include __DIR__ . '/component/footer.php';

运行实例 »

点击 "运行实例" 按钮查看在线实例


实例

<?php
// 加载公共头部
include __DIR__ . '/component/header.php';

//get the cate_id to show which pages
$integerId = intval( $_GET['cate_id'] );

echo '<ol>';
foreach ( $cates as $cate ):
	if ( $integerId == $cate['cate_id'] ) {
		echo '<h2>' . $cate['name'] . '</h2>';
		foreach ( $foods as $food ):
			if ( $cate['cate_id'] == $food['cate_id'] ) {
				echo '<li><a href="detail.php?foods_id=' . $food['foods_id'] . '">' . $food['name'] . '</a></li>';
			}
		endforeach;
	}
endforeach;
echo '</ol>';


// 加载公共底部
include __DIR__ . '/component/footer.php';

运行实例 »

点击 "运行实例" 按钮查看在线实例


实例

<?php
// 加载公共头部
include __DIR__ . '/component/header.php';

$integerId = intval( $_GET['foods_id'] );

foreach ( $foods as $food ):
	if ( $integerId == $food['foods_id'] ) {
		echo $food['name'] . '<br>';
		echo $food['detail'];
	}
endforeach;

// 加载公共底部
include __DIR__ . '/component/footer.php';

运行实例 »

点击 "运行实例" 按钮查看在线实例


作業上傳到github中。

https://github.com/beebb0128/php.cn

Correction status:qualified

Teacher's comments:1. 四个小时完成, 对于新人来说是正常的; 2. 英文注释比较另类, 但目前还是推荐使用中文 3. GitHub打开太慢了,你在HK,咱们比不了
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post