Correcting teacher:天蓬老师
Correction status:qualified
Teacher's comments:看来你是一个动漫迷, 不错
<?php include __DIR__ . '/inc/public_header.php' ;?>
<?php
function getrankey($goods,$num)
{
$rankeys = array_rand($goods, $num);
foreach ($rankeys as $key) {
$rankey[] = $goods[$key];
}
return $rankey;
}
$rankey = getrankey($goods,3);
?>
<main>
<div class="goods">
<div class="title">
<a href="">推荐</a>
</div>
<div class="content">
<!-- 推荐 -->
<?php foreach ($rankey as $ran) : ?>
<div>
<a href="<?php echo $ran['url'] ?>"><img src="<?php echo STATIC_PATH . $ran['pic'] ?>" alt=""></a>
<a href=""><?php echo $ran['name'] ?></a>
</div>
<?php endforeach; ?>
</div>
</div>
<!-- 其他分类 -->
<?php foreach ($categories as $categorie) : ?>
<div class="goods">
<div class="title">
<a href=""><?php echo $categorie['name'] ?></a>
</div>
<div class="content">
<?php foreach ($goods as $good) : ?>
<?php if ($categorie['id'] === $good['cid']) : ?>
<div>
<a href="<?php echo $good['url'] ?>"><img src="<?php echo STATIC_PATH . $good['pic'] ?>" alt=""></a>
<a href=""><?php echo $good['name'] ?></a>
</div>
<?php endif; ?>
<?php endforeach; ?>
</div>
</div>
<?php endforeach; ?>
</main>
<?php include __DIR__ . '/inc/public_footer.php' ?>
<?php include __DIR__ . '/inc/public_header.php' ?>
<?php
$cid = $_GET['cid'];
function getcatName($cid,$categories)
{
foreach ($categories as $category) {
if ($category['id'] === intval($cid))
{
$cateName = $category['name'];
}
}
return $cateName;
}
function getcatgood($cid,$goods)
{
foreach ($goods as $good) {
if ($good['cid'] === intval($cid)) {
$rankey[] = $good;
}
}
return $rankey;
}
$cateName = getcatName($cid,$categories);
$rankey = getcatgood($cid,$goods);
?>
<main>
<!-- 其他分类 -->
<div class="goods">
<div class="title">
<a href=""><?php echo $cateName ?></a>
</div>
<div class="content">
<?php foreach ($rankey as $ran) : ?>
<div>
<a href="<?php echo $ran['url'] ?>"><img src="<?php echo STATIC_PATH . $ran['pic'] ?>" alt=""></a>
<a href=""><?php echo $ran['name'] ?></a>
</div>
<?php endforeach; ?>
</div>
</div>
</main>
<?php include __DIR__ . '/inc/public_footer.php' ?>
<?php include __DIR__ . '/inc/public_header.php' ?>
<?php
$id = $_GET['id'];
function getgood($id,$goods)
{
foreach ($goods as $good) {
if ($good['id'] === intval($id)) {
$shangp = $good;
}
}
return $shangp;
}
$shangp = getgood($id,$goods);
?>
<!-- 详情页 -->
<main>
<div class="goods">
<div class="content">
<div>
<a href="<?php echo $shangp['url'] ?>"><img src="<?php echo STATIC_PATH . $shangp['pic'] ?>" alt=""></a>
<a href=""><?php echo $shangp['name'] ?></a>
</div>
<p>
<?php echo $shangp['detail'] ?>
</p>
</div>
</div>
</main>
<?php include __DIR__ . '/inc/public_footer.php' ?>
<?php include __DIR__ . '/inc/public_header.php' ?>
<?php
$rankeys = array_rand($goods, 6);
foreach ($rankeys as $key) {
$rankey[] = $goods[$key];
}
?>
<main>
<!-- 推� -->
<div class="goods">
<div class="title">
<a href="">推�</a>
</div>
<div class="content">
<?php foreach ($rankey as $ran) : ?>
<div>
<a href="<?php echo $ran['url'] ?>"><img src="<?php echo STATIC_PATH . $ran['pic'] ?>" alt=""></a>
<a href=""><?php echo $ran['name'] ?></a>
</div>
<?php endforeach; ?>
</div>
</div>
</main>
<?php include __DIR__ . '/inc/public_footer.php' ?>
/* 初始化 */
* {
margin: 0;
padding: 0;
}
/* 链接默认样式 */
a {
text-decoration: none;
color: #333;
}
a:hover {
color: lightcoral;
}
/* 整体布局:flex */
body {
width: 100vw;
height: 100vh;
font-size: 13px;
min-width: 500px;
display: flex;
flex-direction: column;
}
/*全部顶部导航区*/
.public-header {
height: 44px;
background-color: black;
/*导航链接不要太靠边*/
padding: 0 20px;
/*弹性布局*/
display: flex;
/*水平排列且不换行*/
flex-flow: row nowrap;
}
/*设置链接样式*/
.public-header a {
/*垂直居中*/
line-height: 44px;
padding: 0 10px;
color: #cccccc;
}
/*鼠标悬停链接的样式*/
.public-header > a:hover {
background-color: #fff;
color: black;
}
/*最后二个链接:登录,注册居右对齐*/
.public-header > span{
margin-left: auto;
}
/*设置字体图标*/
.public-header > span i {
/*字体图标大小必须用font-size,不支持width,height*/
font-size: 16px;
/*字体图标可使用color属性设置前景色*/
color: #ccc;
padding-right: 10px;
}
/*底部*/
.public-footer {
/*基本样式*/
background-color: #282c31;
color: #959ba2;
padding: 30px;
/*网格布局*/
display: grid;
/*水平: 列模板*/
grid-template-columns: 130px 550px 400px;
/*垂直: 行模板*/
grid-template-rows: 30px 160px;
/*网格区域模板*/
grid-template-areas: 'link link rwm'
'logo info rwm';
/*水平居中对齐*/
justify-content: center;
}
/*页脚头部导航*/
.public-footer > div:first-of-type {
/*网格区域名称*/
grid-area: link;
}
/*设置头部导航中的链接样式*/
.public-footer > div:first-of-type a {
color: #959ba2;
padding: 5px 15px;
}
/*LOGO占位符样式*/
.public-footer span {
/*网格区域名称*/
grid-area: logo;
/*基本样式*/
font-size: 30px;
margin-top: 40px;
margin-left: 130px;
}
/*版权备案号等其它信息*/
.public-footer > div:nth-of-type(3) {
/*网格区域名称*/
grid-area: info;
/*基本样式*/
font-size: 13px;
line-height: 40px;
}
/*二维码样式*/
.public-footer > div:last-of-type {
/*网格区域名称*/
grid-area: rwm;
/*基本样式*/
border-left: 1px solid #000;
padding-left: 40px;
}
/*二维码上的描述文本样式*/
.public-footer > div:last-of-type p {
font-size: 13px;
margin-left: 20px;
}
/*二维码图片样式*/
.public-footer > div:last-of-type img {
margin-top: 50px;
margin-left: 150px;
}
/* 中间主体 */
body > main {
margin: 20px 0;
flex: 1;
display: flex;
flex-direction: column;
/* 实现头尾固定, 中间滚动 */
overflow-y: scroll;
}
body > main > .goods {
margin: 20px 0;
display: flex;
flex-direction: column;
}
body > main > .goods > .title {
align-self: center;
border-bottom: 3px solid lightcoral;
margin: 10px 0;
}
body > main > .goods > .title a {
font-size: 23px;
}
body > main > .goods > .content {
display: grid;
grid-template-columns: repeat(3, 160px);
grid-gap: 20px;
place-content: start center;
}
body > main a {
font-size: 13px;
}
body > main div span {
color: red;
}
/* 所有图片样式 */
main img {
width: 160px;
/* height: 160px; */
}
main img:hover {
border: 1px solid #aaa;
box-sizing: border-box;
}
/* 购买按钮 */
body > main button {
font-size: 13px;
width: 50px;
height: 20px;
background-color: seagreen;
color: white;
border: none;
outline:none;
border-radius: 5px;
margin-left: 10px;
}
body > main button:hover {
background-color: lightcoral;
cursor: pointer;
box-shadow: 0 0 3px #888;
}
html {
height: 100%;
}
body {
min-height: 100%;
display: grid;
grid-template-rows: 1fr auto;
}
.footer {
grid-row-start: 2;
grid-row-end: 3;
}
if
单分支替代语法:
<?php if(表达式):?>
HTML代码
<?php endif;>
if
双分支替代语法:
<?php if(表达式):?>
HTML代码
<?php else: ?>
HTML代码
<?php endif;>
if
多分支替代语法:
<?php if(表达式):?>
HTML代码
<?php elseif(表达式):?>
HTML代码
<?php else: ?>
HTML代码
<?php endif;>
for
替代语法:
<?php for(初始化循环计数器;循环判断条件;更新循环计数器):?>
HTML代码
<?php endfor;>
foreach
替代语法:
<?php foreach(数组 as 变量):?>
HTML代码
<?php endforeach;>
while
替代语法:
<?php while(表达式):?>
HTML代码
<?php endwhile;>
switch
替代语法:
<?php switch(变量): case 值1:?>
HTML代码
<?php break; ?>
<?php case 值2:?>
HTML代码
<?php break; ?>
<?php endswitch;>
include | include_once:
包含一个外部文件到页面,失败时不会终止程序,加上once仅能包含一次,防止重复加载包含
require |require_once:
包含一个外部文件到页面,失败时会终止程序,加上once仅能包含一次,防止重复加载包含
因为工作原因很久没写作业了,课程也拉下很多,也太久没有复习也没学习前面的知识也遗忘很多,趁春节补补作业,这次作业基本上是跟着老师敲出来的,下次什么时候能有时间再写作业也说不定,接下来的作业估计也要很久很久才能交上了,每天都有新知识,还要对前面的进行复习真的忙不过来,最开始害怕的事情还是发生了,两者根本无法平衡,主要时间和精力只能放在工作上,这边只能在找时间从头开始,慢慢学吧,希望今年有时间能够有更多的时间放到这吧,作业会慢慢补上