Google Chart在SQL String之间添加每一天

时间:2013-07-15 21:29:53

标签: php mysql foreach google-visualization

这是代码

$search_sql = "SELECT * FROM logs WHERE from_unixtime(timestamp, '%e %b %Y') BETWEEN '$from_date_string' AND '$to_date_string' ";

$search_result = mysql_query($search_sql) or die(mysql_error());
$search_total = mysql_num_rows($search_result);

var dataTable2 = google.visualization.arrayToDataTable([
  ["Date From", "Result"],
  ["' . $from_date_string .'",  ' . $search_total2 . '],
  < INSERT LOOP EACH DATE BETWEEN HERE >
  ["' . $to_date_string .'",  ' . $search_total3 . ']
]);

基本上我想将Inbetween Days添加到Google Chart DataTable2中的From和To。

我认为这将是一个foreach记录,但我不知道从哪里开始。

日期格式示例 - 1月13日

while ($row = mysql_fetch_array($search_result_loop)){
echo "['Date',  200], \n";
}

我需要上面的这一点,以便每天在From和To日期之间给我

1 个答案:

答案 0 :(得分:0)

考虑使用查询按日期对结果进行分组,例如:

select 
    from_unixtime(timestamp, '%e %b %Y') as somedate, 
    count(*) as 'searchtotal'
from logs
where from_unixtime(timestamp, '%e %b %Y') BETWEEN '$from_date_string' AND '$to_date_string'
group by somedate