
<?php
$conn = @mysql_connect("主机","用户名", "密码")//连接数据库服务器
if($conn){
die('连不上数据库')
}
@mysql_select_db("数据名",$conn)
or die('引用了不存在的数据库')//选择数据库
mysql_query("set names gbk", $conn)//设置数据库连接编码
$_tobay = date('Y-m-d 00:00:00',time())//和下面的两行是你上面的
$_tomorrow = date('Y-m-d 23:59:59',time())
$res = mysql_query("SELECT * FROM tv_order WHERE tv_date BETWEEN $_tobay AND $_tomorrow", $conn)// 执行SQL语句,就是你刚才上面的那个,它返回的是一个资源, 不是直接的数据
while($r = mysql_fetch_assoc($res)){// 或 mysql_fetch_array, 可同时得到数字和字段关联的数组, mysql_fetch_row 只是取得数字关联的数组
foreach($r as $k =>$v){ //
echo "$k =>$v \t"//输出数据
}
echo "<br/>\n"//换一行输出
}
mysql_free_result($res)//释放资源
mysql_close($conn)//关闭数据库
?>
select hour(create_time) AS saleHour, count(id) AS saleCountfrom tableName where date_format(create_time, ‘%Y-%m-%d’ ) = ‘2021-09-07’
group by hour(create_time)
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)