Blogger Information
Blog 13
fans 0
comment 0
visits 10300
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
0110-数组实现动态网页
Original
700 people have browsed it

效果图





代码

首页

  1. <?php include __DIR__ . '/inc/public_header.php' ;?>
  2. <?php
  3. function getrankey($goods,$num)
  4. {
  5. $rankeys = array_rand($goods, $num);
  6. foreach ($rankeys as $key) {
  7. $rankey[] = $goods[$key];
  8. }
  9. return $rankey;
  10. }
  11. $rankey = getrankey($goods,3);
  12. ?>
  13. <main>
  14. <div class="goods">
  15. <div class="title">
  16. <a href="">推荐</a>
  17. </div>
  18. <div class="content">
  19. <!-- 推荐 -->
  20. <?php foreach ($rankey as $ran) : ?>
  21. <div>
  22. <a href="<?php echo $ran['url'] ?>"><img src="<?php echo STATIC_PATH . $ran['pic'] ?>" alt=""></a>
  23. <a href=""><?php echo $ran['name'] ?></a>
  24. </div>
  25. <?php endforeach; ?>
  26. </div>
  27. </div>
  28. <!-- 其他分类 -->
  29. <?php foreach ($categories as $categorie) : ?>
  30. <div class="goods">
  31. <div class="title">
  32. <a href=""><?php echo $categorie['name'] ?></a>
  33. </div>
  34. <div class="content">
  35. <?php foreach ($goods as $good) : ?>
  36. <?php if ($categorie['id'] === $good['cid']) : ?>
  37. <div>
  38. <a href="<?php echo $good['url'] ?>"><img src="<?php echo STATIC_PATH . $good['pic'] ?>" alt=""></a>
  39. <a href=""><?php echo $good['name'] ?></a>
  40. </div>
  41. <?php endif; ?>
  42. <?php endforeach; ?>
  43. </div>
  44. </div>
  45. <?php endforeach; ?>
  46. </main>
  47. <?php include __DIR__ . '/inc/public_footer.php' ?>

列表

  1. <?php include __DIR__ . '/inc/public_header.php' ?>
  2. <?php
  3. $cid = $_GET['cid'];
  4. function getcatName($cid,$categories)
  5. {
  6. foreach ($categories as $category) {
  7. if ($category['id'] === intval($cid))
  8. {
  9. $cateName = $category['name'];
  10. }
  11. }
  12. return $cateName;
  13. }
  14. function getcatgood($cid,$goods)
  15. {
  16. foreach ($goods as $good) {
  17. if ($good['cid'] === intval($cid)) {
  18. $rankey[] = $good;
  19. }
  20. }
  21. return $rankey;
  22. }
  23. $cateName = getcatName($cid,$categories);
  24. $rankey = getcatgood($cid,$goods);
  25. ?>
  26. <main>
  27. <!-- 其他分类 -->
  28. <div class="goods">
  29. <div class="title">
  30. <a href=""><?php echo $cateName ?></a>
  31. </div>
  32. <div class="content">
  33. <?php foreach ($rankey as $ran) : ?>
  34. <div>
  35. <a href="<?php echo $ran['url'] ?>"><img src="<?php echo STATIC_PATH . $ran['pic'] ?>" alt=""></a>
  36. <a href=""><?php echo $ran['name'] ?></a>
  37. </div>
  38. <?php endforeach; ?>
  39. </div>
  40. </div>
  41. </main>
  42. <?php include __DIR__ . '/inc/public_footer.php' ?>

详情

  1. <?php include __DIR__ . '/inc/public_header.php' ?>
  2. <?php
  3. $id = $_GET['id'];
  4. function getgood($id,$goods)
  5. {
  6. foreach ($goods as $good) {
  7. if ($good['id'] === intval($id)) {
  8. $shangp = $good;
  9. }
  10. }
  11. return $shangp;
  12. }
  13. $shangp = getgood($id,$goods);
  14. ?>
  15. <!-- 详情页 -->
  16. <main>
  17. <div class="goods">
  18. <div class="content">
  19. <div>
  20. <a href="<?php echo $shangp['url'] ?>"><img src="<?php echo STATIC_PATH . $shangp['pic'] ?>" alt=""></a>
  21. <a href=""><?php echo $shangp['name'] ?></a>
  22. </div>
  23. <p>
  24. <?php echo $shangp['detail'] ?>
  25. </p>
  26. </div>
  27. </div>
  28. </main>
  29. <?php include __DIR__ . '/inc/public_footer.php' ?>

推荐

  1. <?php include __DIR__ . '/inc/public_header.php' ?>
  2. <?php
  3. $rankeys = array_rand($goods, 6);
  4. foreach ($rankeys as $key) {
  5. $rankey[] = $goods[$key];
  6. }
  7. ?>
  8. <main>
  9. <!-- 推� -->
  10. <div class="goods">
  11. <div class="title">
  12. <a href="">推�</a>
  13. </div>
  14. <div class="content">
  15. <?php foreach ($rankey as $ran) : ?>
  16. <div>
  17. <a href="<?php echo $ran['url'] ?>"><img src="<?php echo STATIC_PATH . $ran['pic'] ?>" alt=""></a>
  18. <a href=""><?php echo $ran['name'] ?></a>
  19. </div>
  20. <?php endforeach; ?>
  21. </div>
  22. </div>
  23. </main>
  24. <?php include __DIR__ . '/inc/public_footer.php' ?>

CSS

  1. /* 初始化 */
  2. * {
  3. margin: 0;
  4. padding: 0;
  5. }
  6. /* 链接默认样式 */
  7. a {
  8. text-decoration: none;
  9. color: #333;
  10. }
  11. a:hover {
  12. color: lightcoral;
  13. }
  14. /* 整体布局:flex */
  15. body {
  16. width: 100vw;
  17. height: 100vh;
  18. font-size: 13px;
  19. min-width: 500px;
  20. display: flex;
  21. flex-direction: column;
  22. }
  23. /*全部顶部导航区*/
  24. .public-header {
  25. height: 44px;
  26. background-color: black;
  27. /*导航链接不要太靠边*/
  28. padding: 0 20px;
  29. /*弹性布局*/
  30. display: flex;
  31. /*水平排列且不换行*/
  32. flex-flow: row nowrap;
  33. }
  34. /*设置链接样式*/
  35. .public-header a {
  36. /*垂直居中*/
  37. line-height: 44px;
  38. padding: 0 10px;
  39. color: #cccccc;
  40. }
  41. /*鼠标悬停链接的样式*/
  42. .public-header > a:hover {
  43. background-color: #fff;
  44. color: black;
  45. }
  46. /*最后二个链接:登录,注册居右对齐*/
  47. .public-header > span{
  48. margin-left: auto;
  49. }
  50. /*设置字体图标*/
  51. .public-header > span i {
  52. /*字体图标大小必须用font-size,不支持width,height*/
  53. font-size: 16px;
  54. /*字体图标可使用color属性设置前景色*/
  55. color: #ccc;
  56. padding-right: 10px;
  57. }
  58. /*底部*/
  59. .public-footer {
  60. /*基本样式*/
  61. background-color: #282c31;
  62. color: #959ba2;
  63. padding: 30px;
  64. /*网格布局*/
  65. display: grid;
  66. /*水平: 列模板*/
  67. grid-template-columns: 130px 550px 400px;
  68. /*垂直: 行模板*/
  69. grid-template-rows: 30px 160px;
  70. /*网格区域模板*/
  71. grid-template-areas: 'link link rwm'
  72. 'logo info rwm';
  73. /*水平居中对齐*/
  74. justify-content: center;
  75. }
  76. /*页脚头部导航*/
  77. .public-footer > div:first-of-type {
  78. /*网格区域名称*/
  79. grid-area: link;
  80. }
  81. /*设置头部导航中的链接样式*/
  82. .public-footer > div:first-of-type a {
  83. color: #959ba2;
  84. padding: 5px 15px;
  85. }
  86. /*LOGO占位符样式*/
  87. .public-footer span {
  88. /*网格区域名称*/
  89. grid-area: logo;
  90. /*基本样式*/
  91. font-size: 30px;
  92. margin-top: 40px;
  93. margin-left: 130px;
  94. }
  95. /*版权备案号等其它信息*/
  96. .public-footer > div:nth-of-type(3) {
  97. /*网格区域名称*/
  98. grid-area: info;
  99. /*基本样式*/
  100. font-size: 13px;
  101. line-height: 40px;
  102. }
  103. /*二维码样式*/
  104. .public-footer > div:last-of-type {
  105. /*网格区域名称*/
  106. grid-area: rwm;
  107. /*基本样式*/
  108. border-left: 1px solid #000;
  109. padding-left: 40px;
  110. }
  111. /*二维码上的描述文本样式*/
  112. .public-footer > div:last-of-type p {
  113. font-size: 13px;
  114. margin-left: 20px;
  115. }
  116. /*二维码图片样式*/
  117. .public-footer > div:last-of-type img {
  118. margin-top: 50px;
  119. margin-left: 150px;
  120. }
  121. /* 中间主体 */
  122. body > main {
  123. margin: 20px 0;
  124. flex: 1;
  125. display: flex;
  126. flex-direction: column;
  127. /* 实现头尾固定, 中间滚动 */
  128. overflow-y: scroll;
  129. }
  130. body > main > .goods {
  131. margin: 20px 0;
  132. display: flex;
  133. flex-direction: column;
  134. }
  135. body > main > .goods > .title {
  136. align-self: center;
  137. border-bottom: 3px solid lightcoral;
  138. margin: 10px 0;
  139. }
  140. body > main > .goods > .title a {
  141. font-size: 23px;
  142. }
  143. body > main > .goods > .content {
  144. display: grid;
  145. grid-template-columns: repeat(3, 160px);
  146. grid-gap: 20px;
  147. place-content: start center;
  148. }
  149. body > main a {
  150. font-size: 13px;
  151. }
  152. body > main div span {
  153. color: red;
  154. }
  155. /* 所有图片样式 */
  156. main img {
  157. width: 160px;
  158. /* height: 160px; */
  159. }
  160. main img:hover {
  161. border: 1px solid #aaa;
  162. box-sizing: border-box;
  163. }
  164. /* 购买按钮 */
  165. body > main button {
  166. font-size: 13px;
  167. width: 50px;
  168. height: 20px;
  169. background-color: seagreen;
  170. color: white;
  171. border: none;
  172. outline:none;
  173. border-radius: 5px;
  174. margin-left: 10px;
  175. }
  176. body > main button:hover {
  177. background-color: lightcoral;
  178. cursor: pointer;
  179. box-shadow: 0 0 3px #888;
  180. }
  181. html {
  182. height: 100%;
  183. }
  184. body {
  185. min-height: 100%;
  186. display: grid;
  187. grid-template-rows: 1fr auto;
  188. }
  189. .footer {
  190. grid-row-start: 2;
  191. grid-row-end: 3;
  192. }

流程控制替代语法

if单分支替代语法:

  1. <?php if(表达式):?>
  2. HTML代码
  3. <?php endif;>

if双分支替代语法:

  1. <?php if(表达式):?>
  2. HTML代码
  3. <?php else: ?>
  4. HTML代码
  5. <?php endif;>

if多分支替代语法:

  1. <?php if(表达式):?>
  2. HTML代码
  3. <?php elseif(表达式):?>
  4. HTML代码
  5. <?php else: ?>
  6. HTML代码
  7. <?php endif;>

for替代语法:

  1. <?php for(初始化循环计数器;循环判断条件;更新循环计数器):?>
  2. HTML代码
  3. <?php endfor;>

foreach替代语法:

  1. <?php foreach(数组 as 变量):?>
  2. HTML代码
  3. <?php endforeach;>

while替代语法:

  1. <?php while(表达式):?>
  2. HTML代码
  3. <?php endwhile;>

switch替代语法:

  1. <?php switch(变量): case 1:?>
  2. HTML代码
  3. <?php break; ?>
  4. <?php case 2:?>
  5. HTML代码
  6. <?php break; ?>
  7. <?php endswitch;>

包含文件

include | include_once:包含一个外部文件到页面,失败时不会终止程序,加上once仅能包含一次,防止重复加载包含

require |require_once:包含一个外部文件到页面,失败时会终止程序,加上once仅能包含一次,防止重复加载包含


因为工作原因很久没写作业了,课程也拉下很多,也太久没有复习也没学习前面的知识也遗忘很多,趁春节补补作业,这次作业基本上是跟着老师敲出来的,下次什么时候能有时间再写作业也说不定,接下来的作业估计也要很久很久才能交上了,每天都有新知识,还要对前面的进行复习真的忙不过来,最开始害怕的事情还是发生了,两者根本无法平衡,主要时间和精力只能放在工作上,这边只能在找时间从头开始,慢慢学吧,希望今年有时间能够有更多的时间放到这吧,作业会慢慢补上

Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:看来你是一个动漫迷, 不错
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