Blogger Information
Blog 53
fans 3
comment 0
visits 55277
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
12月-前端大作业-PHP培训线上九期班
邯郸易住宋至刚
Original
935 people have browsed it

一、项目分析

准备先在首页实现动态数据

1、创建数据表

数据表有:栏目表、导航表(这两者本来也可以合并的)、图片表、新闻列表

2、数据查询

查询使用PDO预处理查询

3、代码分段

首页代码分为

index.php

  1. <?php
  2. include 'inc/header.php';
  3. include 'inc/banner.php';
  4. include 'inc/news.php';
  5. include 'inc/images.php';
  6. include 'inc/trade.php';
  7. include 'inc/footer.php';

header.php

  1. <?php
  2. require 'DB.php';
  3. ?>
  4. <!DOCTYPE html>
  5. <html lang="en">
  6. <head>
  7. <meta charset="UTF-8">
  8. <title>网站首页</title>
  9. <!-- <link rel="stylesheet" href="static/css/reset.css">-->
  10. <link rel="stylesheet" href="static/font/iconfont.css">
  11. <link rel="stylesheet" href="static/css/index.css">
  12. </head>
  13. <body>
  14. <!--公共顶部导航区-->
  15. <header>
  16. <?php foreach ($cates as $cate) :?>
  17. <a href=""><?php echo $cate['name']; ?></a>
  18. <?php endforeach; ?>
  19. <span><a href=""><i class="iconfont icon-huiyuan2"></i>登陆</a><a href="">免费注册</a></span>
  20. </header>
  21. <!--logo+搜索框+快捷入口区-->
  22. <div class="logo">
  23. <img src="<?php echo $logo[0]['url']?>" alt="">
  24. <label>
  25. <input type="search">
  26. <a href="" class="iconfont icon-jinduchaxun"></a>
  27. </label>
  28. <span>
  29. <a href="" class="iconfont icon-huiyuan1"></a>
  30. <a href="" class="iconfont icon-danmu"></a>
  31. <a href="" class="iconfont icon-duoxuankuang"></a>
  32. <a href="" class="iconfont icon-jishufuwu"></a>
  33. <a href="" class="iconfont icon-peiwangyindao"></a>
  34. <a href="" class="iconfont icon-wenjianjia"></a>
  35. <a href="" class="iconfont icon-huiyuan1"></a>
  36. </span>
  37. </div>
  38. <!--主导航区-->
  39. <nav>
  40. <div>
  41. <span class="iconfont icon-gongdan"></span>
  42. <span>资讯 <br> 看学</span>
  43. <?php foreach ($navs as $nav) :?>
  44. <a href=""><?php echo $nav['name']; ?></a>
  45. <?php endforeach; ?>
  46. </div>
  47. <div>
  48. <span class="iconfont icon-renwujincheng"></span>
  49. <span>资讯 <br> 看学</span>
  50. <?php foreach ($navs as $nav) :?>
  51. <a href=""><?php echo $nav['name']; ?></a>
  52. <?php endforeach; ?>
  53. </div>
  54. <div>
  55. <span class="iconfont icon-gongdan"></span>
  56. <span>资讯 <br> 看学</span>
  57. <?php foreach ($navs as $nav) :?>
  58. <a href=""><?php echo $nav['name']; ?></a>
  59. <?php endforeach; ?>
  60. </div>
  61. <div>
  62. <span class="iconfont icon-DOC"></span>
  63. <span>资讯 <br> 看学</span>
  64. <?php foreach ($navs as $nav) :?>
  65. <a href=""><?php echo $nav['name']; ?></a>
  66. <?php endforeach; ?>
  67. </div>
  68. </nav>
  1. <!--合作网站-->
  2. <div class="title" style="background:#fff">
  3. <span>合作网站</span>
  4. </div>
  5. <div class="my-links">
  6. <a href="https://www.php.cn">php中文网</a>
  7. <a href="https://www.html.cn">html中文网</a>
  8. <a href="https://www.py.cn">python中文网</a>
  9. <a href="https://www.php.cn">php中文网</a>
  10. <a href="https://www.html.cn">html中文网</a>
  11. <a href="https://www.py.cn">python中文网</a>
  12. <a href="https://www.php.cn">php中文网</a>
  13. <a href="https://www.html.cn">html中文网</a>
  14. <a href="https://www.py.cn">python中文网</a>
  15. <a href="https://www.php.cn">php中文网</a>
  16. <a href="https://www.html.cn">html中文网</a>
  17. <a href="https://www.py.cn">python中文网</a>
  18. <a href="https://www.py.cn">python中文网</a>
  19. <a href="https://www.php.cn">php中文网</a>
  20. <a href="https://www.html.cn">html中文网</a>
  21. <a href="https://www.py.cn">python中文网</a>
  22. <a href="https://www.php.cn">php中文网</a>
  23. <a href="https://www.html.cn">html中文网</a>
  24. <a href="https://www.py.cn">python中文网</a>
  25. <a href="https://www.php.cn">php中文网</a>
  26. <a href="https://www.html.cn">html中文网</a>
  27. <a href="https://www.py.cn">python中文网</a>
  28. <a href="https://www.php.cn">php中文网</a>
  29. <a href="https://www.html.cn">html中文网</a>
  30. <a href="https://www.py.cn">python中文网</a>
  31. <a href="https://www.py.cn">python中文网</a>
  32. </div>
  33. <!--页底部-->
  34. <footer>
  35. <div>
  36. <a href="">简介</a>
  37. <a href="">联系我们</a>
  38. <a href="">招聘信息</a>
  39. <a href="">友情链接</a>
  40. <a href="">用户服务协议</a>
  41. <a href="">隐私权声明</a>
  42. <a href="">法律投诉声明</a>
  43. </div>
  44. <div><span>LOGO</span></div>
  45. <div>
  46. <p>2019 fengniao.com. All rights reserved . 安徽闹着玩有限公司(无聊网)版权所有</p>
  47. <p>皖ICP证150110号 京ICP备14323013号-2 皖公网安备110108024357788号</p>
  48. <p>违法和不良信息举报电话: 0551-1234567 举报邮箱: admin@baidu.com</p>
  49. </div>
  50. <div>
  51. <p>关注公众号</p>
  52. <img src="<?=$erwei[0]['url'];?>" alt="">
  53. </div>
  54. </footer>
  55. </body>
  56. </html>

banner.php

  1. <!--轮播图-->
  2. <?php
  3. require 'connect.php';
  4. //获取轮播图片
  5. $sql = "SELECT * FROM `picture` WHERE `name`= 'banner2'";
  6. $stmt = $pdo->prepare($sql);
  7. $stmt -> execute();
  8. $banner = $stmt ->fetchAll(PDO::FETCH_ASSOC);
  9. //获取轮播右边图片
  10. $sql = "SELECT * FROM `picture` WHERE `name`= 'banner-right'";
  11. $stmt = $pdo->prepare($sql);
  12. $stmt -> execute();
  13. $banner_right = $stmt ->fetchAll(PDO::FETCH_ASSOC);
  14. ?>
  15. <div class="slider">
  16. <img src="<?php echo $banner[0]['url'] ?>" alt="">
  17. <img src="<?php echo $banner_right[0]['url'] ?>" alt="">
  18. </div>

news.php

  1. <!--新闻资讯区-->
  2. <div class="news">
  3. <div class="title">
  4. <a>新闻资讯</a>
  5. <a href="">更多</a>
  6. </div>
  7. <div class="content">
  8. <div class="pic">
  9. <a href=""><img src="<?php echo $n_1[0]['url'] ?>" alt="" class="first-img"></a>
  10. <a href=""><img src="<?php echo $n_2[0]['url'] ?>" alt=""></a>
  11. <a href=""><img src="<?php echo $n_3[0]['url'] ?>" alt=""></a>
  12. <a href="">三星Note10/10+发布 <br> 搭载挖孔前摄</a>
  13. <a href="">小米公布6400万 <br> 和1亿像素手机信息</a>
  14. </div>
  15. <div class="list">
  16. <a href="">性价比广角 腾龙17-28F2.8评测</a>
  17. <ul>
  18. <?php foreach ($news as $new) : ?>
  19. <li><span>[新闻]</span><a href=""><?php echo $new['title'];?></a></li>
  20. <?php endforeach;?>
  21. <?php foreach ($news as $new) : ?>
  22. <li><span>[新闻]</span><a href=""><?php echo $new['title'];?></a></li>
  23. <?php endforeach;?>
  24. <!-- <li><span>[新闻]</span><a href="">Entaniya宣布推出Super 35 PL卡口鱼眼镜头</a></li>
  25. <li><span>[新闻]</span><a href="">轻便灵巧可变形 JOBY入门迷你三脚架套装试用</a></li>
  26. <li><span>[新闻]</span><a href="">乐摄宝Photo Active BP 300 AW背包评测</a></li>
  27. <li><span>[新闻]</span><a href="">佳能注册相机无线充电和眼控对焦专利</a></li>
  28. <li><span>[新闻]</span><a href="">Entaniya宣布推出Super 35 PL卡口鱼眼镜头</a></li>
  29. <li><span>[新闻]</span><a href="">轻便灵巧可变形 JOBY入门迷你三脚架套装试用</a></li>
  30. <li><span>[新闻]</span><a href="">乐摄宝Photo Active BP 300 AW背包评测</a></li>
  31. <li><span>[新闻]</span><a href="">乐摄宝Photo Active BP 300 AW背包评测</a></li> -->
  32. </ul>
  33. </div>
  34. <div class="list">
  35. <a href="">性价比广角 腾龙17-28F2.8评测</a>
  36. <ul>
  37. <?php foreach ($news as $new) : ?>
  38. <li><span>[新闻]</span><a href=""><?php echo $new['title'];?></a></li>
  39. <?php endforeach;?>
  40. <?php foreach ($news as $new) : ?>
  41. <li><span>[新闻]</span><a href=""><?php echo $new['title'];?></a></li>
  42. <?php endforeach;?>
  43. <!-- <li><span>[新闻]</span><a href="">佳能注册相机无线充电和眼控对焦专利</a></li>
  44. <li><span>[新闻]</span><a href="">Entaniya宣布推出Super 35 PL卡口鱼眼镜头</a></li>
  45. <li><span>[新闻]</span><a href="">轻便灵巧可变形 JOBY入门迷你三脚架套装试用</a></li>
  46. <li><span>[新闻]</span><a href="">乐摄宝Photo Active BP 300 AW背包评测</a></li>
  47. <li><span>[新闻]</span><a href="">佳能注册相机无线充电和眼控对焦专利</a></li>
  48. <li><span>[新闻]</span><a href="">Entaniya宣布推出Super 35 PL卡口鱼眼镜头</a></li>
  49. <li><span>[新闻]</span><a href="">轻便灵巧可变形 JOBY入门迷你三脚架套装试用</a></li>
  50. <li><span>[新闻]</span><a href="">乐摄宝Photo Active BP 300 AW背包评测</a></li>
  51. <li><span>[新闻]</span><a href="">乐摄宝Photo Active BP 300 AW背包评测</a></li> -->
  52. </ul>
  53. </div>
  54. </div>
  55. </div>

images.php

  1. <!--二手交易专区-->
  2. <div class="title">
  3. <span>二手交易</span>
  4. </div>
  5. <div class="second-hand">
  6. <div>
  7. <a href="">抢好货</a>
  8. <span>0低价, 便捷,安全,快速</span>
  9. </div>
  10. <div>
  11. <span>热门分类</span>
  12. <a href="">美女写真</a>
  13. <a href="">日本美女</a>
  14. <a href="">美国美女</a>
  15. <a href="">国内美女</a>
  16. <a href="">AV美女</a>
  17. </div>
  18. <?php foreach ($shop1 as $s1) : ?>
  19. <a href=""><img src="<?php echo $s1['url']; ?>" alt="" width="176" height="122"></a>
  20. <?php endforeach; ?>
  21. <!-- <a href=""><img src="static/images/shop/shop1.jpg" alt="" width="176" height="120"></a>
  22. <a href=""><img src="static/images/shop/shop2.jpg" alt="" width="176" height="120"></a>
  23. <a href=""><img src="static/images/shop/shop3.jpg" alt="" width="176" height="120"></a>
  24. <a href=""><img src="static/images/shop/shop4.jpg" alt="" width="176" height="120"></a> -->
  25. <?php foreach ($shop1 as $s1) : ?>
  26. <div class="detail">
  27. <a href=""><?php echo $s1['title']; ?></a>
  28. <div>
  29. <a href="">
  30. <span>&yen; 333</span>
  31. <span>美女</span>
  32. </a>
  33. </div>
  34. </div>
  35. <?php endforeach; ?>
  36. <!-- <div class="detail">
  37. <a href=""><?php echo $s1['title']; ?></a>
  38. <div>
  39. <a href="">
  40. <span>&yen; 333</span>
  41. <span>美女</span>
  42. </a>
  43. </div>
  44. </div>
  45. <div class="detail">
  46. <a href="">美女性感写真海报墙面贴画艺术装画</a>
  47. <div>
  48. <a href="">
  49. <span>&yen; 333</span>
  50. <span>美女</span>
  51. </a>
  52. </div>
  53. </div>
  54. <div class="detail">
  55. <a href="">美女性感写真海饰画酒吧卧室贴画图画</a>
  56. <div>
  57. <a href="">
  58. <span>&yen; 333</span>
  59. <span>美女</span>
  60. </a>
  61. </div>
  62. </div>
  63. <div class="detail">
  64. <a href="">美女性感写真海饰画酒吧卧室贴画图画</a>
  65. <div>
  66. <a href="">
  67. <span>&yen; 333</span>
  68. <span>美女</span>
  69. </a>
  70. </div>
  71. </div> -->
  72. <?php foreach ($shop2 as $s2) : ?>
  73. <a href=""><img src="<?php echo $s2['url']; ?>" alt="" width="176" height="122"></a>
  74. <?php endforeach; ?>
  75. <!-- <a href=""><img src="static/images/shop/shop1.jpg" alt="" width="176" height="120"></a>
  76. <a href=""><img src="static/images/shop/shop2.jpg" alt="" width="176" height="120"></a>
  77. <a href=""><img src="static/images/shop/shop3.jpg" alt="" width="176" height="120"></a>
  78. <a href=""><img src="static/images/shop/shop4.jpg" alt="" width="176" height="120"></a> -->
  79. <?php foreach ($shop1 as $s1) : ?>
  80. <div class="detail">
  81. <a href=""><?php echo $s1['title']; ?></a>
  82. <div>
  83. <a href="">
  84. <span>&yen; 333</span>
  85. <span>美女</span>
  86. </a>
  87. </div>
  88. </div>
  89. <?php endforeach; ?>
  90. <!-- <a href=""><img src="static/images/shop/shop5.jpg" alt="" width="176" height="120"></a>
  91. <a href=""><img src="static/images/shop/shop6.jpg" alt="" width="176" height="120"></a>
  92. <a href=""><img src="static/images/shop/shop7.jpg" alt="" width="176" height="120"></a>
  93. <a href=""><img src="static/images/shop/shop8.jpg" alt="" width="176" height="120"></a>
  94. <div class="detail">
  95. <a href="">美女性感写真海报墙艺术装饰画贴画图画</a><br>
  96. <div>
  97. <a href="">
  98. <span>&yen; 333</span>
  99. <span>美女</span>
  100. </a>
  101. </div>
  102. </div>
  103. <div class="detail">
  104. <a href="">美女性感写真海报墙面贴画艺术装画</a>
  105. <div>
  106. <a href="">
  107. <span>&yen; 333</span>
  108. <span>美女</span>
  109. </a>
  110. </div>
  111. </div>
  112. <div class="detail">
  113. <a href="">美女性感写真海饰画酒吧卧室贴画图画</a>
  114. <div>
  115. <a href="">
  116. <span>&yen; 333</span>
  117. <span>美女</span>
  118. </a>
  119. </div>
  120. </div>
  121. <div class="detail">
  122. <a href="">美女性感写真海饰画酒吧卧室贴画图画</a>
  123. <div>
  124. <a href="">
  125. <span>&yen; 333</span>
  126. <span>美女</span>
  127. </a>
  128. </div>
  129. </div> -->
  130. <div>
  131. <?php foreach ($ads as $ad) : ?>
  132. <a href=""><img src="<?php echo $ad['url']; ?>" alt="" width="180" height="112"></a>
  133. <?php endforeach; ?>
  134. <!-- <a href=""><img src="<?php echo $ad['url']; ?>" alt="" width="180" height="112"></a>
  135. <a href=""><img src="static/images/ad/2.png" alt="" width="180" height="112"></a>
  136. <a href=""><img src="static/images/ad/3.png" alt="" width="180" height="112"></a>
  137. <a href=""><img src="static/images/ad/4.png" alt="" width="180" height="112"></a>
  138. <a href=""><img src="static/images/ad/image.png" alt="" width="393" height="56"></a>
  139. <a href=""><img src="static/images/ad/ad2.jpg" alt="" width="393" height="56"></a> -->
  140. <?php foreach ($ads2 as $ad2) : ?>
  141. <a href=""><img src="<?php echo $ad2['url']; ?>" alt="" width="393" height="56"></a>
  142. <?php endforeach; ?>
  143. </div>
  144. </div>

trade.php

  1. <!--二手交易专区-->
  2. <div class="title">
  3. <span>二手交易</span>
  4. </div>
  5. <div class="second-hand">
  6. <div>
  7. <a href="">抢好货</a>
  8. <span>0低价, 便捷,安全,快速</span>
  9. </div>
  10. <div>
  11. <span>热门分类</span>
  12. <a href="">美女写真</a>
  13. <a href="">日本美女</a>
  14. <a href="">美国美女</a>
  15. <a href="">国内美女</a>
  16. <a href="">AV美女</a>
  17. </div>
  18. <?php foreach ($shop1 as $s1) : ?>
  19. <a href=""><img src="<?php echo $s1['url']; ?>" alt="" width="176" height="122"></a>
  20. <?php endforeach; ?>
  21. <!-- <a href=""><img src="static/images/shop/shop1.jpg" alt="" width="176" height="120"></a>
  22. <a href=""><img src="static/images/shop/shop2.jpg" alt="" width="176" height="120"></a>
  23. <a href=""><img src="static/images/shop/shop3.jpg" alt="" width="176" height="120"></a>
  24. <a href=""><img src="static/images/shop/shop4.jpg" alt="" width="176" height="120"></a> -->
  25. <?php foreach ($shop1 as $s1) : ?>
  26. <div class="detail">
  27. <a href=""><?php echo $s1['title']; ?></a>
  28. <div>
  29. <a href="">
  30. <span>&yen; 333</span>
  31. <span>美女</span>
  32. </a>
  33. </div>
  34. </div>
  35. <?php endforeach; ?>
  36. <!-- <div class="detail">
  37. <a href=""><?php echo $s1['title']; ?></a>
  38. <div>
  39. <a href="">
  40. <span>&yen; 333</span>
  41. <span>美女</span>
  42. </a>
  43. </div>
  44. </div>
  45. <div class="detail">
  46. <a href="">美女性感写真海报墙面贴画艺术装画</a>
  47. <div>
  48. <a href="">
  49. <span>&yen; 333</span>
  50. <span>美女</span>
  51. </a>
  52. </div>
  53. </div>
  54. <div class="detail">
  55. <a href="">美女性感写真海饰画酒吧卧室贴画图画</a>
  56. <div>
  57. <a href="">
  58. <span>&yen; 333</span>
  59. <span>美女</span>
  60. </a>
  61. </div>
  62. </div>
  63. <div class="detail">
  64. <a href="">美女性感写真海饰画酒吧卧室贴画图画</a>
  65. <div>
  66. <a href="">
  67. <span>&yen; 333</span>
  68. <span>美女</span>
  69. </a>
  70. </div>
  71. </div> -->
  72. <?php foreach ($shop2 as $s2) : ?>
  73. <a href=""><img src="<?php echo $s2['url']; ?>" alt="" width="176" height="122"></a>
  74. <?php endforeach; ?>
  75. <!-- <a href=""><img src="static/images/shop/shop1.jpg" alt="" width="176" height="120"></a>
  76. <a href=""><img src="static/images/shop/shop2.jpg" alt="" width="176" height="120"></a>
  77. <a href=""><img src="static/images/shop/shop3.jpg" alt="" width="176" height="120"></a>
  78. <a href=""><img src="static/images/shop/shop4.jpg" alt="" width="176" height="120"></a> -->
  79. <?php foreach ($shop1 as $s1) : ?>
  80. <div class="detail">
  81. <a href=""><?php echo $s1['title']; ?></a>
  82. <div>
  83. <a href="">
  84. <span>&yen; 333</span>
  85. <span>美女</span>
  86. </a>
  87. </div>
  88. </div>
  89. <?php endforeach; ?>
  90. <!-- <a href=""><img src="static/images/shop/shop5.jpg" alt="" width="176" height="120"></a>
  91. <a href=""><img src="static/images/shop/shop6.jpg" alt="" width="176" height="120"></a>
  92. <a href=""><img src="static/images/shop/shop7.jpg" alt="" width="176" height="120"></a>
  93. <a href=""><img src="static/images/shop/shop8.jpg" alt="" width="176" height="120"></a>
  94. <div class="detail">
  95. <a href="">美女性感写真海报墙艺术装饰画贴画图画</a><br>
  96. <div>
  97. <a href="">
  98. <span>&yen; 333</span>
  99. <span>美女</span>
  100. </a>
  101. </div>
  102. </div>
  103. <div class="detail">
  104. <a href="">美女性感写真海报墙面贴画艺术装画</a>
  105. <div>
  106. <a href="">
  107. <span>&yen; 333</span>
  108. <span>美女</span>
  109. </a>
  110. </div>
  111. </div>
  112. <div class="detail">
  113. <a href="">美女性感写真海饰画酒吧卧室贴画图画</a>
  114. <div>
  115. <a href="">
  116. <span>&yen; 333</span>
  117. <span>美女</span>
  118. </a>
  119. </div>
  120. </div>
  121. <div class="detail">
  122. <a href="">美女性感写真海饰画酒吧卧室贴画图画</a>
  123. <div>
  124. <a href="">
  125. <span>&yen; 333</span>
  126. <span>美女</span>
  127. </a>
  128. </div>
  129. </div> -->
  130. <div>
  131. <?php foreach ($ads as $ad) : ?>
  132. <a href=""><img src="<?php echo $ad['url']; ?>" alt="" width="180" height="112"></a>
  133. <?php endforeach; ?>
  134. <!-- <a href=""><img src="<?php echo $ad['url']; ?>" alt="" width="180" height="112"></a>
  135. <a href=""><img src="static/images/ad/2.png" alt="" width="180" height="112"></a>
  136. <a href=""><img src="static/images/ad/3.png" alt="" width="180" height="112"></a>
  137. <a href=""><img src="static/images/ad/4.png" alt="" width="180" height="112"></a>
  138. <a href=""><img src="static/images/ad/image.png" alt="" width="393" height="56"></a>
  139. <a href=""><img src="static/images/ad/ad2.jpg" alt="" width="393" height="56"></a> -->
  140. <?php foreach ($ads2 as $ad2) : ?>
  141. <a href=""><img src="<?php echo $ad2['url']; ?>" alt="" width="393" height="56"></a>
  142. <?php endforeach; ?>
  143. </div>
  144. </div>

数据库连接文件:connect.php

<?php
//数据库连接配置
$dbParams = [
‘type’ => ‘mysql’,
‘host’ => ‘127.0.0.1’,
‘dbname’ => ‘shop’,
‘username’=> ‘root’,
‘password’=> ‘111’
];

  1. //配置数据源dsn
  2. $dsn = "{$dbParams['type']}:host={$dbParams['host']};dbname={$dbParams['dbname']}";
  3. try {
  4. //连接数据库
  5. $pdo = new PDO($dsn,$dbParams['username'],$dbParams['password']);
  6. } catch (PDOException $e) {
  7. //连接失败返回信息
  8. die('Connection Failed' .$e->getMessage());
  9. }

数据库查询软件:DB.php

  1. <?php
  2. include __DIR__ .'/connect.php';
  3. $sql = "SELECT * FROM `picture` WHERE `name`= 'LOGO'";
  4. $stmt = $pdo->prepare($sql);
  5. $stmt -> execute();
  6. $logo = $stmt ->fetchAll(PDO::FETCH_ASSOC);
  7. //获取栏目信息
  8. $sql = 'SELECT `id`,`name` FROM `category`';
  9. $stmt = $pdo->prepare($sql);
  10. $stmt->execute();
  11. $cates = $stmt->fetchAll(PDO::FETCH_ASSOC);
  12. //var_dump($cates);
  13. $cate_count = count($cates); // 栏目数量
  14. //$title = $cates->title;
  15. //获取导航信息
  16. $sql = 'SELECT `id`,`name` FROM `nav`';
  17. $stmt = $pdo->prepare($sql);
  18. $stmt->execute();
  19. $navs = $stmt->fetchAll(PDO::FETCH_ASSOC);
  20. $navs_count = count($navs); // 栏目数量
  21. //获取新闻图片1
  22. $sql = "SELECT * FROM `picture` WHERE `name`= 'n-1'";
  23. $stmt = $pdo->prepare($sql);
  24. $stmt -> execute();
  25. $n_1 = $stmt ->fetchAll(PDO::FETCH_ASSOC);
  26. //获取新闻图片2
  27. $sql = "SELECT * FROM `picture` WHERE `name`= 'n-2'";
  28. $stmt = $pdo->prepare($sql);
  29. $stmt -> execute();
  30. $n_2 = $stmt ->fetchAll(PDO::FETCH_ASSOC);
  31. //获取新闻图片3
  32. $sql = "SELECT * FROM `picture` WHERE `name`= 'n-3'";
  33. $stmt = $pdo->prepare($sql);
  34. $stmt -> execute();
  35. $n_3 = $stmt ->fetchAll(PDO::FETCH_ASSOC);
  36. //获取新闻区标题列表
  37. $sql = "SELECT * FROM `news`";
  38. $stmt = $pdo->prepare($sql);
  39. $stmt -> execute();
  40. $news = $stmt ->fetchAll(PDO::FETCH_ASSOC);
  41. //获取图片列表
  42. $sql = "SELECT * FROM `picture` WHERE `id` > 11 LIMIT 2";
  43. $stmt = $pdo->prepare($sql);
  44. $stmt -> execute();
  45. $pictures1 = $stmt ->fetchAll(PDO::FETCH_ASSOC);
  46. for ($i=0; $i < count($pictures1) ; $i++) {
  47. $url1[] = $pictures1[$i]['url'];
  48. $title1[] = $pictures1[$i]['title'];
  49. }
  50. //获取出售图片
  51. $sql = "SELECT * FROM `picture` WHERE `id` > 19 LIMIT 4";
  52. $stmt = $pdo->prepare($sql);
  53. $stmt -> execute();
  54. $shop1 = $stmt ->fetchAll(PDO::FETCH_ASSOC);
  55. //获取出售图片
  56. $sql = "SELECT * FROM `picture` WHERE `id` > 23 LIMIT 4";
  57. $stmt = $pdo->prepare($sql);
  58. $stmt -> execute();
  59. $shop2 = $stmt ->fetchAll(PDO::FETCH_ASSOC);
  60. //获取广告图片
  61. $sql = "SELECT * FROM `picture` WHERE `id` > 29 LIMIT 4";
  62. $stmt = $pdo->prepare($sql);
  63. $stmt -> execute();
  64. $ads = $stmt ->fetchAll(PDO::FETCH_ASSOC);
  65. //获取广告图片
  66. $sql = "SELECT * FROM `picture` WHERE `id` > 33 LIMIT 2";
  67. $stmt = $pdo->prepare($sql);
  68. $stmt -> execute();
  69. $ads2 = $stmt ->fetchAll(PDO::FETCH_ASSOC);
  70. //获取二维码
  71. $sql = "SELECT * FROM `picture` WHERE `name` = 'erwei-code'";
  72. $stmt = $pdo->prepare($sql);
  73. $stmt -> execute();
  74. $erwei = $stmt ->fetchAll(PDO::FETCH_ASSOC);
  75. //var_dump($erwei);
  76. //echo $erwei[0]['url'];
  77. //var_dump($url1,$title1);
  78. /*$url1 = [];
  79. $title1 = [];
  80. foreach ($pictures1 as $p1) {
  81. for ($i=0; $i < count($pictures1); $i++) {
  82. $url1[] = $p1[$i]['url'];
  83. $title1[] = $p1[$i]['title1'];
  84. }
  85. }
  86. var_dump($url1,$pictures2);*/
  87. $sql = "SELECT * FROM `picture` WHERE `id` > 13 LIMIT 2";
  88. $stmt = $pdo->prepare($sql);
  89. $stmt -> execute();
  90. $pictures2 = $stmt ->fetchAll(PDO::FETCH_ASSOC);
  91. for ($i=0; $i < count($pictures2) ; $i++) {
  92. $url2[] = $pictures2[$i]['url'];
  93. $title2[] = $pictures2[$i]['title'];
  94. }
  95. /*foreach ($pictures2 as $p2) {
  96. $url2[] = $p2['url'];
  97. $title1[] = $p2['title1'];
  98. }*/
  99. $sql = "SELECT * FROM `picture` WHERE `id` > 15 LIMIT 2";
  100. $stmt = $pdo->prepare($sql);
  101. $stmt -> execute();
  102. $pictures2 = $stmt ->fetchAll(PDO::FETCH_ASSOC);
  103. for ($i=0; $i < count($pictures2) ; $i++) {
  104. $url3[] = $pictures2[$i]['url'];
  105. $title3[] = $pictures2[$i]['title'];
  106. }
  107. $sql = "SELECT * FROM `picture` WHERE `id` > 17 LIMIT 2";
  108. $stmt = $pdo->prepare($sql);
  109. $stmt -> execute();
  110. $pictures2 = $stmt ->fetchAll(PDO::FETCH_ASSOC);
  111. for ($i=0; $i < count($pictures2) ; $i++) {
  112. $url4[] = $pictures2[$i]['url'];
  113. $title4[] = $pictures2[$i]['title'];
  114. }
  115. //var_dump($news);
  116. ?>

4、结果

二、总结

1、关于项目分析

没有任何经验,不知道分析什么

2、关于数据的使用

数据库查询后返回的结果类型不是很清楚,不知道返回的是一维数组还是二维数组,在遍历的时候遇到了很大的问题

3、关于单条记录查询

想查到一个指定记录不知道用什么办法,感觉用的是最LOW的查询办法

4、关于URL跳转

超级链接,网页跳来跳去的,一会儿就把自己搞晕了,不知道有什么好的办法

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