PHP DATE逻辑问题

时间:2014-01-28 17:42:56

标签: php mysql arrays date

现在我站在logig proplem面前......当我尝试用作日常交通时,我该如何做到最好?

2014-01-26:xx traffic 2014-01-27:xx traffic 2014-01-28:xx traffic

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
?>
<?php 

function formatBytes($size, $precision = 2)
{
    $base = log($size) / log(1024);
    $suffixes = array('', 'k', 'MB', 'GB', 'TB');   

    return round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)];
}


$db=mysql_connect("localhost","traffic","....."); 
mysql_select_db("traffic",$db);
$qry = "SELECT SUM(bytes) AS total FROM acct_v4 
          WHERE SUBSTRING(stamp_updated,9,2) = '28' ";


$select = mysql_query($qry);
$result = mysql_fetch_array($select);


echo 'Summe: '.formatBytes($result['total']);  
//echo $result['total'];


?>

我是否能够最好地告诉我它计算所有数据并在平日给我回复

1 个答案:

答案 0 :(得分:0)

使用Day of date_fieldgroup by date_field

$qry = "SELECT stamp_updated, SUM(bytes) AS total FROM acct_v4 "
       . " WHERE DAY(stamp_updated) = '28' "
       . " GROUP BY stamp_updated";

在所有匹配日期的28天结果记录。