无为清净楼资源网 Design By www.qnjia.com
简易教程
假设我们制作的是分班情况查询程序,将使用PHP7的环境以PDO的方式连接MySQL。
通过学号和姓名查询自己所在班级。
先来介绍文件结构和数据库结构:
PHP:
config.php 存放数据库配置信息
cx.php 查询程序
index.html 用户界面
结构如图
MySQL:
表名:data
字段:1.Sid 2.name 3.class
结构如图
准备就绪,开始吧,现在!
首先构建用户界面(index.html),两个简单的编辑框加上一个简单的按钮:
<!DOCTYPE html> <html lang="cn"> <head> <meta charset="UTF-8"> <title>分班查询系统</title> </head> <body> <form action="cx.php" method="post"> <p>学号:<input type="text" name="xuehao"></p> <p>姓名: <input type="text" name="xingming"></p> <p><input type="submit" name="submit" value="查询"></p> </form> </body> </html>
好嘞,接下来配置数据库信息(config.php)吧
<"localhost";//主机的IP地址 $db_username="root";//数据库用户名 $db_password="123456";//数据库密码 $db_name = "data";
然后去编写我们的主程序(cx.php)
<"Content-Type: text/html; charset=utf8"); if(!isset($_POST["submit"])) { exit("未检测到表单提交"); }//检测是否有submit操作 include ("config.php"); $Sid = $_POST['Sid'];//post获得学号表单值 $name = $_POST['name'];//post获得姓名表单值 echo "<table style='border: solid 1px black;'>"; echo "<tr><th>学号</th><th>姓名</th><th>班级</th></tr>"; class TableRows extends RecursiveIteratorIterator { function __construct($it) { parent::__construct($it, self::LEAVES_ONLY); } function current() { return "<td style='width:150px;border:1px solid black;'>" . parent::current() . "</td>"; } function beginChildren() { echo "<tr>"; } function endChildren() { echo "</tr>" . "\n"; } } try { $conn = new PDO("mysql:host=$server;dbname=$db_name", $db_username, $db_password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $conn->prepare("SELECT Sid, name, class FROM data where Sid=$Sid and name='$name'"); $stmt->execute(); // 设置结果集为关联数组 $result = $stmt->setFetchMode(PDO::FETCH_ASSOC); foreach (new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k => $v) { echo $v; } } catch (PDOException $e) { echo "Error: " . $e->getMessage(); } $conn = null; echo "</table>";
到此程序就写完啦
来试试看吧
总结
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年09月25日
2024年09月25日
- 黄心懋1991-轻忧郁【滚石】【WAV+CUE】
- 群星.2000-大地金曲世纪回顾2CD【大地】【WAV+CUE】
- 王菲.1996-浮躁(2024环球MQA-UHQCD限量版)【环球】【WAV+CUE】
- 群星.2022-传家电视剧原声带【东阳欢娱】【FLAC分轨】
- 《摇滚教父 伍佰黄金精选 2CD》 [WAV+CUE][1GB]
- 《凤凰传奇 我从草原来》[WAV/分轨][400MB]
- 《叶倩文 真心真意过一生》[WAV+CUE][400MB]
- 潘越云.1985-世间女子(滚石25周年经典复刻版)【滚石】【WAV+CUE】
- 陈柏宇.2009-CANT.BE.HALF【SONY】【WAV+CUE】
- 李明依.1989-小女生【滚石】【WAV+CUE】
- 《李荣浩 新时代创作新人王》[WAV分轨][310MB]
- 《黑鸭子与马头琴 史上最动听草原音乐》[WAV+CUE][320MB]
- 《汽车发烧音乐精选CD18》[FLAC+CUE][7.1G]
- 郑希怡.2004-Perfect.Date【英皇娱乐】【FLAC分轨】
- 群星.1994-宝丽金超级孖宝2CD【宝丽金】【WAV+CUE】