【发布时间】:2014-10-09 20:15:14
【问题描述】:
我想在 Google Charts 的帮助下从 SQL 查询中创建一个时间线。我使用以下代码创建了编码为 json 的数组。问题是,$table 只包含这段代码末尾的最后一条记录,但我有不止一条记录。
$rows = array();
$table = array();
$table['cols'] = array(
array('id' => '', 'label' => 'Name', 'pattern' => '', 'type' => 'string'),
array('id' => '', 'label' => 'Start', 'pattern' => '', 'type' => 'date'),
array('id' => '', 'label' => 'End', 'pattern' => '', 'type' => 'date') );
while($r = mysql_fetch_assoc($results)) {
$name=$r['Name']; $date=$r['Date'];
$start=$r['start'];
$end=$r['end'];
$year=date("Y", strtotime($date));
$month=date("m", strtotime($date));
$day=date("d", strtotime($date));
$start_h=date("H", strtotime($start));
$start_min=date("i", strtotime($start));
$start_sec=date("s", strtotime($start));
$end_h=date("H", strtotime($end));
$end_min=date("i", strtotime($end));
$end_sec=date("s", strtotime($end));
$start_merged = "Date(".$year.",".$month.",".$day.",".$start_h.",".$start_min.",".$start_sec.")";
$end_merged = "Date(".$year.",".$month.",".$day.",".$end_h.",".$end_min.",".$end_sec.")";
$rows = array();
$temp = array();
$temp[] = array('v' => (string) $name);
$temp[] = array('v' => (string) $start_merged);
$temp[] = array('v' => (string) $end_merged);
$rows[] = array('c' => $temp);
}
$table['rows'] = $rows;
【问题讨论】:
标签: php google-visualization timeline