Blogger Information
Blog 18
fans 0
comment 0
visits 10865
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP实现动态页面1.10作业
- 迷舍人
Original
791 people have browsed it

模仿老师的图片展写的

总结重点就是把循环掌握好 思路清晰 找准入口 比如说 找到id 在获取到当前商品在的数组 来获得需要的信息 遍历出来

首页效果图


代码

  1. <?php include __DIR__ . '/inc/public_header.php'?>
  2. <?php
  3. //// 获取秒杀商品的键
  4. // $msgoodskey = array_rand($goods,6);
  5. //// 根据键名获取里面的内容
  6. // foreach ($msgoodskey as $key){
  7. // $msgoods[] = $goods[$key];
  8. // }
  9. function huoqu($goods,$num){
  10. $msgoodskey = array_rand($goods,6);
  11. foreach ($msgoodskey as $key){
  12. $msgoods[] = $goods[$key];
  13. }
  14. return $msgoods;
  15. }
  16. $msgoods = huoqu($goods,3);
  17. ?>
  18. <!--内容-->
  19. <main>
  20. <!--正在秒杀-->
  21. <div class="goods">
  22. <!--大标题-->
  23. <div class="title">
  24. <a href="">正在秒杀</a>
  25. </div>
  26. </div>
  27. <div class="content">
  28. <!--商品信息 -->
  29. <?php foreach ($msgoods as $msgood) : ?>
  30. <div>
  31. <a href="<?php echo $msgood['url'] ?>">
  32. <img src="<?php echo STATIC_PATH . $msgood['pic'] ?>" alt="">
  33. </a>
  34. <span>
  35. <a href=""><?php echo $msgood['name'] ?></a>
  36. <span><?php echo $msgood['price'] ?></span>
  37. <button>购买</button>
  38. </span>
  39. </div>
  40. <?php endforeach ?>
  41. </div>
  42. <?php foreach ($daohangs as $daohang) : ?>
  43. <div class="goods">
  44. <!--大标题-->
  45. <div class="title">
  46. <a href=""><?php echo $daohang['name'] ?></a>
  47. </div>
  48. </div>
  49. <div class="content">
  50. <?php foreach ($goods as $good) : ?>
  51. <?php if ($daohang['id'] === $good['cid']) : ?>
  52. <div>
  53. <a href="<?php echo $good['url'] ?>">
  54. <img src="<?php echo STATIC_PATH . $good['pic'] ?>" alt="">
  55. </a>
  56. <span>
  57. <a href=""><?php echo $good['name'] ?></a>
  58. <span><?php echo $good['price'] ?></span>
  59. <button>购买</button>
  60. </span>
  61. </div>
  62. <?php endif ?>
  63. <?php endforeach ?>
  64. </div>
  65. <?php endforeach; ?>
  66. </main>
  67. <?php include __DIR__ . '/inc/public_footer.php'?>

详情页效果图

代码

  1. <?php include __DIR__ . '/inc/public_header.php'?>
  2. <?php
  3. // 获取栏目
  4. $id = $_GET['id'];
  5. // 根据商品id 获取当前信息
  6. foreach ($goods as $good){
  7. if ($good['id'] === intval($id)){
  8. $dangqian = $good;
  9. }
  10. }
  11. ?>
  12. <!--内容-->
  13. <main>
  14. <div class="goods">
  15. <!--大标题-->
  16. <div class="title">
  17. <a href=""><?php echo $mingcheng ?></a>
  18. </div>
  19. </div>
  20. <div class="content">
  21. <div>
  22. <a href="<?php echo $dangqian['url'] ?>">
  23. <img src="<?php echo STATIC_PATH . $dangqian['pic'] ?>" alt="">
  24. </a>
  25. <p><?php echo $dangqian['detail'] ?></p>
  26. <span>
  27. <a href=""><?php echo $dangqian['name'] ?></a>
  28. <span><?php echo $dangqian['price'] ?></span>
  29. <button>购买</button>
  30. </span>
  31. </div>
  32. </div>
  33. </main>
  34. <?php include __DIR__ . '/inc/public_footer.php'?>

秒杀效果图

  1. <?php include __DIR__ . '/inc/public_header.php'?>
  2. <?php
  3. // 获取秒杀商品的键
  4. $msgoodskey = array_rand($goods,6);
  5. // 根据键名获取里面的内容
  6. foreach ($msgoodskey as $key){
  7. $msgoods[] = $goods[$key];
  8. }
  9. ?>
  10. <!--内容-->
  11. <main>
  12. <!--正在秒杀-->
  13. <div class="goods">
  14. <!--大标题-->
  15. <div class="title">
  16. <a href="">正在秒杀</a>
  17. </div>
  18. </div>
  19. <div class="content">
  20. <!--商品信息 -->
  21. <?php foreach ($msgoods as $msgood) : ?>
  22. <div>
  23. <a href="<?php echo $msgood['url'] ?>">
  24. <img src="<?php echo STATIC_PATH . $msgood['pic'] ?>" alt="">
  25. </a>
  26. <span>
  27. <a href=""><?php echo $msgood['name'] ?></a>
  28. <span><?php echo $msgood['price'] ?></span>
  29. <button>购买</button>
  30. </span>
  31. </div>
  32. <?php endforeach ?>
  33. </div>
  34. </main>
  35. <?php include __DIR__ . '/inc/public_footer.php'?>
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