数据表的结构:
其中time为unix时间
实现通过php页面输入一个这样格式2008-03-15 23:52:13-2009-03-15 23:52:13的时间段查询。
将查询页面的本地时间2009-03-15 23:52:13转换为unix时间1237132333
时间time2*1000作为time2,进行select * from table where ptime >=time1 and ptime <=time2;
关键代码:
//echo $pTimes;
//echo $utcpTimes;
//
//echo $utcpTime;
//参数过滤并生成SQL------------------------
if($name != null){
$a = " and name like '%$name%'";}
if($pTimeb != null){
$b = " and pTime >= '$utcpTimeb'";}
if($pTimes != null){
$c = " and pTime = '$mNumberb'";}
if($mNumberb != null){
$e = " and mNumber 生成sql语句";
echo $q;
echo " ";
echo " ";
$result = mysql_query($q, $link);
echo "结果反馈";
//$result = mysql_query("SELECT * FROM pay");
//对查询结果中返回的时间进行秒换算,并转成本地时间
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
$unixpTime=$row[7]/1000;
echo "";
floor($unixpTime);
$aa= floor($unixpTime);
echo $aa;
//$aa='0123456789';
$query1 = mysql_query("SELECT FROM_UNIXpTime($aa)");
while ($row1 = mysql_fetch_array($query1, MYSQL_NUM))
{
// printf (" pTime %s ", $row1[0]);
$starpTime=$row1[0] ;
}
echo " ";
//打印输出结果
printf ("玩家姓名: %s 充值卡号: %s 充值时间: $starpTime 是否生效: %s 充值金额: %s ", $row[0], $row[1], $row[3] , $row[4], $row[5]);
printf ("充值卡号: %s 玩家姓名: %s 充值金额: %s 充值时间: %s ", $row[0], $row[1], $row[5], $row[7]);
echo " ";
}
mysql_free_result($result);
?>