我正在尝试显示一些给定日期范围的统计数据。在表行中有许多 ID 并试图计算它自己的 ID 的总分钟数。
当前返回值如下:
{"id":"25","minute":13}
{"id":"17","minute":12}
{"id":"16","minute":10}
{"id":"17","minute":10}
{"id":"16","minute":4}
{"id":"34","minute":5}
{"id":"17","minute":21}
{"id":"30","minute":12}
{"id":"30","minute":13}
{"id":"30","minute":50}
控制器
public function actionStats() {
if (isset($_POST['begin'], $_POST['end'])) {
$begin = strtotime($_POST['begin']);
$end = strtotime($_POST['end']);
$Criteria = new CDbCriteria();
$Criteria->condition = "created >= $begin and created <= $end and status=1";
$transcripts = Transcripts::model()->findAll($Criteria);
foreach($transcripts as $transcript) {
$op = $transcript->opID;
$minute = $transcript->ended - $transcript->created;
echo json_encode(array("id" => $op, "minute" => floor($minute/60)));
}
}
}