HTML+PHP+MySQL实现新闻列表模块(1+X Web前端开发中级 例题)——初稿
2023-09-11 14:15:12 时间
📄题目要求
- 阅读下列说明、效果图、MySQL数据库操作和代码,进行动态网页开发,填写(1)至(15)代码。
🧩说明
- 该程序为一个html和php混合的新闻列表模块,使用PHP语言,采用MySQL数据库和mysqli扩展。项目名称为itwang,包括web目录,config目录,class目录,public目录。
其中web目录存放information.php文件。public目录存放图片资源。config目录存放配置文件,class目录存放各种类。
进行动态网页开发,补全代码,在(1)至(15)处填入正确的内容。
🧩效果图
💻HTML+PHP代码
<?php // 在(1)处补齐代码,开启session (1); // 在(2)处补齐代码,使用相对路径,以../开头,导入config.php文件 require_once"(2)"; //自动加载类 spl_autoload_register(function($name){ require_once"../class/{$name}.class.php"; }); ?> <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no"> <title>项目实战</title> <link rel="stylesheet" href="./dist/css/bootstrap.min.css"> <link rel="stylesheet" type="text/css" href="css/common.css" /> <link rel="stylesheet" href="css/style.css"> </head> <body> <?php require_once"./common/header.html";?> <div id="information"> <div class="container"> <div class="row"> <div class="col-md-8"> <div class="container-fluid" style="padding:0;"> <?php //连接数据库遍历数据 // 在(3),(4),(5),(6)位置根据配置文件中常量分别填写域名,用户名,密码,数据库 $mysqli=new mysqli((3),(4),(5),(6)); if ($mysqli->connect_errno) { die('连接失败: ' . $mysqli->connect_error); } // 设置字符编码 $mysqli->query("set names utf8"); //在(7)处补全代码,计算数据表中数据总数 $total=$mysqli->query("select id from information where status=1")->(7); //根据上下文,在(8)处补全代码,设置每页条数的变量 (8)=5; //在(9)处补全代码,向上取整 $maxpage=(9)($total/$showrow); //当前页面,如果从前端通过get方法获取了当前页,就给$currentP,否则就是1 $currentP=empty($_GET['page']) ? 1 : ($_GET['page']>$maxpage?$maxpage:$_GET['page']); // mysqli预处理语句 // 在(10)处填写当前页变量,在(11)处填写每页条数变量 if($stmt=$mysqli->prepare("select * from information where status=1 limit ".(( (10)-1)* $showrow)." , {(11)}")){ $stmt->execute(); //执行语句 $stmt->bind_result($id,$title,$content,$author,$image,$time,$status); //绑定字段 // 在(12)处填写条件循环关键字 (12) ($stmt->fetch()) { ?> <div class="row info-content"> <div class="col-md-5 col-sm-5 col-xs-5"> <img src="../public/<?php echo $image; ?>" class="img-responsive" alt="" style='width:300px;height:150px;'> </div> <div class="col-md-7 col-sm-7 col-xs-7"> <h4><?php echo $title; ?></h4> <p class="hidden-xs"><?php echo mb_substr($content, 0,20,"utf-8")."......"; echo "<a href='detail.php?id={$id}'>[阅读全文]</a>"; ?></p> <p><?php echo $author; echo " ".date("Y/m/d",$time); ?></p> </div> </div> <?php } $stmt->close(); } ?> </div> <div> <?php if($total>$showrow){ // 在(13)处补全代码,实例一个分页类,在(14)处填写数据总数的变量名 $page=new (13)((14),$showrow); // 根据page类,分析并填写(15)处调用方法 echo $page->(15)(3,4,5,6,7); } ?> </div> </div> <div class="col-md-4 info-right hidden-xs hidden-sm"> <blockquote> <h2>热门资讯</h2> </blockquote> <div class="container-fluid"> <?php $res=$mysqli->query("select inforid from hot group by inforid order by count(inforid) desc limit 5;"); while ($row=$res->fetch_array()) { //查询最热门 的资讯的详情 $re=$mysqli->query("select * from information where id=".$row[0]); $rows=$re->fetch_array(1); ?> <div class="row"> <div class="col-md-5 col-sm-5 col-xs-5" style="margin: 12px 0; padding: 0"> <img src="/project/public/<?php echo $rows["image"] ;?>" class="img-responsive" alt=""> </div> <div class="col-md-7 col-sm-7 col-xs-7" style="padding-right: 0"> <h4><?php echo $rows["title"] ;?></h4> <p><?php echo $rows["author"] ;echo date("Y/m/d",$rows["time"]);?></p> </div> </div> <?php }; ?> </div> </div> </div> </div> </div> <?php $mysqli->close(); require_once"common/footer.html"; ?> <script src="js/jquery.min.js"></script> <script src="js/bootstrap.min.js"></script> </body> </html>
🎯实现效果
📰完整答案
试题二(30分)
【问题】(30分)
(1)session_start()
(2)../config/config.php
(3)HOST (必须大写)
(4)USER (必须大写)
(5)PSW (必须大写)
(6)DB (必须大写)
(7)num_rows
(8)$showrow
(9)ceil
(10)$currentP
(11)$showrow
(12)while
(13)Page
(14)$total
(15)fpage
(每空2分,共30分)
🎯点赞收藏,防止迷路🔥
相关文章
- What is the difference between utf8mb4 and utf8 charsets in MySQL?
- php之快速入门学习-18(PHP 面向对象)
- 【MySQL高级】Mysql的体系结构概览及存储引擎以及索引的使用
- MySQL 日期时间相关函数整理
- MySQL Replication 主从复制全方位解决方案
- RDBMS SQL 编辑器 | MySQL、Oracle、MariaDB、SQLsever、SQLite、PostgreSQL
- MySQL 日期
- slave have equal MySQL Server UUIDs原因及解决
- 【Linux】linux中自动定时备份mysql数据
- MySQL安装详解(V5.5 For Windows)
- 《PHP和MySQL Web开发从新手到高手(第5版)》一一2.10 让PHP进行输入
- 《PHP、MySQL和Apache入门经典(第5版)》一一1.1 使用第三方的安装包
- 《PHP、MySQL和Apache入门经典(第5版)》一一1.2 Linux/UNIX下的安装
- 《PHP、MySQL和Apache入门经典(第5版)》一1.4 在Mac OS X上安装XAMPP
- 《PHP、MySQL和Apache入门经典(第5版)》一第2章 安装和配置MySQL2.1 MySQL的当前版本和未来版本
- 《PHP、MySQL和Apache入门经典(第5版)》一2.3 在Linux/UNIX上安装MySQL
- CentOS7安装mysql
- 基于php和mysql实现(Web)学生课外活动成果统计系统【100010274】
- 转 【MySQL】常用拼接语句 shell 下执行mysql 命令
- Linux+Mysql+Apache+Php测试环境部署
- Mysql 常用函数集
- liunux mysql MySQL表名不区分大小写的设置方法
- PHP之旅——出发(php+apache+MySQL)
- 【php】Apache无法自己主动跳转却显示文件夹与php无法连接mysql数据库的解决方式
- Mysql error.log报错:Error: Table “mysql”.“innodb_table_stats” not found
- (5.8)mysql高可用系列——MySQL中的GTID复制(实践篇)
- 【叶问】mysql常见问题与面试题
- Mysql中的auto_increment
- Mysql partition by
- CentOS 7修改MySQL 5.6字符集为UTF-8
- Mysql 常用操作