<?php
error_reporting(0);
$m = $_GET['m'];
if (!$m) {
index() ;
} else if ($m == 'more') {
more();
}
/**
* 首页,查询最新一条数据
*/
function index() {
$conn = getConn();
// 查询最大的一条
$result = mysql_query("select * from datavalue5 order by id desc limit 1", $conn);
$arr = array();
while ($row = mysql_fetch_array($result)) {
$arr[] = getRow($row);
}
echo json_encode($arr);
closeConn($conn);
}
/**
* 首页,查询最新一条数据
*/
function more() {
$conn = getConn();
$limit = isset($_GET['limit']) ? addslashes($_GET['limit']) : '2';
$lastId = isset($_GET['lastId']) ? addslashes($_GET['lastId']) : '999999999';
//echo $lastId;
// 查询最大的一条
$result = mysql_query("select * from datavalue5 where id < ". $lastId. " order by id desc limit 1, ". $limit, $conn);
$arr = array();
while ($row = mysql_fetch_array($result)) {
$arr[] = getRow($row);
}
echo json_encode($arr);
closeConn($conn);
}
/**
* 转换结果集
*/
function getRow($rs) {
$row = array(
'id'=>$rs['ID'],
'getdatatime'=>$rs['getdatatime'],
'wirtetime'=>$rs['wirtetime'],
'Number'=>$rs['Number'],
'sequential_probeid'=>$rs['sequential_probeid'],
'probe1'=>number_format($rs['probe1']),
'probe2'=>number_format($rs['probe2']),
'probe3'=>number_format($rs['probe3']),
'probe4'=>number_format($rs['probe4']),
'probe5'=>number_format($rs['probe5']),
'probe6'=>number_format($rs['probe6']),
'probe7'=>number_format($rs['probe7']),
'probe8'=>$rs['probe8'],
'probe9'=>number_format($rs['probe9']),
'probe10'=>number_format($rs['probe10']),
'probe11'=>number_format($rs['probe11']),
'probe12'=>number_format($rs['probe12']),
'probe13'=>number_format($rs['probe13']),
'probe15'=>$rs['probe15']
);
return $row;
}
/**
* 获取连接
*/
function getConn() {
$host = "localhost";
$user = "root";
$pwd = "root";
$db = "test";
$conn = mysql_connect($host, $user, $pwd);
if (!$conn){
die('Could not connect: ' . mysql_error());
}
mysql_select_db($db, $conn);
mysql_set_charset('utf8', $conn);
return $conn;
}
/**
* 关闭连接
*/
function closeConn($conn) {
mysql_close($conn);
}
?>
没有合适的资源?快使用搜索试试~ 我知道了~
PHP单页网站直接连接MYSQL数据库在首页显示数据
共27个文件
png:11个
js:3个
css:2个
需积分: 49 54 下载量 169 浏览量
2015-07-20
16:37:59
上传
评论 3
收藏 578KB RAR 举报
温馨提示
这是工作中的一个小需求做的项目,一个简单的网站,进去首页直接显示的就是MYSQL数据库里的数据。要查询14个数据,每个数据左边都有小图片表示数据意义。运用HTML5+jquery开发,适合手机平板等移动端通过浏览器访问,PC端也可以用浏览器访问。注意要在index.php里修改你自己的数据库接口信息。导入压缩包里的数据库文件到你的数据库。
资源推荐
资源详情
资源评论
收起资源包目录
PHP单页网站连接MYSQL.rar (27个子文件)
PHP单页网站连接MYSQL
bootstrap
css
bootstrap.min.css 120KB
style.css 4KB
index.php 2KB
images
icon_fengxiang.png 76KB
icon_diwen.png 1KB
icon_jiangyuliang.png 49KB
icon_temperature_min.png 1KB
icon_guangzhaodu.png 2KB
icon_UV.png 68KB
icon_pm2.5.jpg 16KB
icon_shidu.png 2KB
icon_CO2.png 54KB
icon_pressure.png 49KB
icon_sun.png 51KB
icon_fengsu.png 48KB
loading.gif 3KB
fonts
glyphicons-halflings-regular.woff 23KB
glyphicons-halflings-regular.woff2 18KB
glyphicons-halflings-regular.ttf 44KB
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.svg 106KB
index.html 1KB
js
bootstrap.min.js 36KB
main.js 5KB
jquery-1.10.1.min.js 91KB
history.html 2KB
数据库文件
datavalue5.sql 2.11MB
共 27 条
- 1
资源评论
强者用结果说话
- 粉丝: 34
- 资源: 16
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功