失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > php和mysql创建数据表及获取内容渲染到前端页面

php和mysql创建数据表及获取内容渲染到前端页面

时间:2022-04-30 10:24:21

相关推荐

php和mysql创建数据表及获取内容渲染到前端页面

后端开发|php教程

mysql,php,数据表

后端开发-php教程

本文主要和大家分享php和mysql创建数据表及获取内容渲染到前端页面的方法,希望能帮助到大家。

PHP会议聊天源码,ubuntu17 dsl,草爬虫怎么图片,php软件互换,温州seo快照lzw

1. mysql命令行创建数据表(表结构):

在线报名系统(多项目版源码,ubuntu 主人登陆,爬虫实践报告 建议,php together,seo答辩文章lzw

linux 网络源码,vscode运行磁盘占用率,ubuntu 短信密钥,tomcat 字符串,1688爬虫违法,php 解析csv,关键词霸屏方案seo博客lzw

源码:

create table myValues( id int(4) not null primary key auto_increment, name char(20) not null, year int(20) not null, sex char(20) not null, class char(20) not null, degree double(16,2));

2. mysql命令行查看表结构:

3.php连接mysqli数据库

$connect = mysqli_connect(localhost, oot, oot); //连接数据库if($connect){echo 连接数据库成功!;}else{echo 连接数据库失败;}//连接数据表mysqli_select_db($connect,lgc);

4. php向数据库插入数据

//向数据库发送操作信息 mysqli_query($connect,set names utf8); mysqli_query($connect,insert into myvalues values(1,"王二",20,"男","13.1班","98.68")); mysqli_query($connect,insert into myvalues values(2,"李三",22,"男","12.5班","88.66")); mysqli_query($connect,insert into myvalues values(3,"小花",16,"女","13.1班","78.32")); mysqli_query($connect,insert into myvalues values(4,"小明",15,"男","12.6班","69.95")); mysqli_query($connect,insert into myvalues values(5,"小刚",18,"男","13.2班","83.75")); mysqli_query($connect,insert into myvalues values(6,"小贝",23,"女","12.3班","93.63"));

5. php向数据库发送查询信息

//像数据库提交查询信息(所有信息) 返回查询到资源句柄$info = mysqli_query($connect,select * from myvalues);

6.php获取在数据库中查询到数据:(重要)

$newArr = array();while($arry = mysqli_fetch_array($info,MYSQLI_ASSOC)){array_push($newArr,$arry);}exit(json_encode($newArr));//获取数据://Array ( [0] => Array ( [id] => 1 [name] => 王二 [year] => 20 [sex] => 男 [class] => 13.1班 [degree] => 98.68 ) [1] => Array ( [id] => 2 [name] => 李三 [year] => 22 [sex] => 男 [class] => 12.5班 [degree] => 88.66 ) [2] => Array ( [id] => 3 [name] => 小花 [year] => 16 [sex] => 女 [class] => 13.1班 [degree] => 78.32 ) [3] => Array ( [id] => 4 [name] => 小明 [year] => 15 [sex] => 男 [class] => 12.6班 [degree] => 69.95 ) [4] => Array ( [id] => 5 [name] => 小刚 [year] => 18 [sex] => 男 [class] => 13.2班 [degree] => 83.75 ) [5] => Array ( [id] => 6 [name] => 小贝 [year] => 23 [sex] => 女 [class] => 12.3班 [degree] => 93.63 ) )//json_encode()之后:[{"id":"1","name":"\u738b\u4e8c","year":"20","sex":"\u7537","class":"13.1\u73ed","degree":"98.68"},{"id":"2","name":"\u674e\u4e09","year":"22","sex":"\u7537","class":"12.5\u73ed","degree":"88.66"},{"id":"3","name":"\u5c0f\u82b1","year":"16","sex":"\u5973","class":"13.1\u73ed","degree":"78.32"},{"id":"4","name":"\u5c0f\u660e","year":"15","sex":"\u7537","class":"12.6\u73ed","degree":"69.95"},{"id":"5","name":"\u5c0f\u521a","year":"18","sex":"\u7537","class":"13.2\u73ed","degree":"83.75"},{"id":"6","name":"\u5c0f\u8d1d","year":"23","sex":"\u5973","class":"12.3\u73ed","degree":"93.63"}]

7. ajax加载数据:

8. 页面显示mysql数据表信息:

相关推荐:

React如何从后端获取数据并渲染到前端?

如果觉得《php和mysql创建数据表及获取内容渲染到前端页面》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。