저는 php, mysql 및 json을 사용하여 데이터를 가져와 테이블 차트를 생성하기 위해 Google API 차트를 사용하는 프로젝트를 진행 중입니다. 이제 mysql databse에서 타임 스탬프 데이터 유형을 사용하는 'synctime'열에 갇혀있어 오류가 발생합니다. "날짜"대신 무엇을 사용해야합니까?
어떤 도움이라도 대단히 감사합니다. 내 코드는 다음과 같습니다.
$sql="SELECT device, recordcount, CONCAT(city, ', ', country) AS `Country`, synctime FROM devices";
$exec = mysqli_query($con,$sql);
mysqli_close($con);
$table = array();
$table['cols'] = array(
//Labels for the chart, these represent the column titles
array('id' => '', 'label' => 'device', 'type' => 'string'),
array('id' => '', 'label' => 'recordcount', 'type' => 'number'),
array('id' => '', 'label' => 'Country', 'type' => 'string'),
array('id' => '', 'label' => 'synctime', 'type' => 'string')
);
$rows = array();
foreach($exec as $row){
$temp = array();
//Values
$temp[] = array('v' => (string) $row['device']);
$temp[] = array('v' => (int) $row['recordcount']);
$temp[] = array('v' => (string) $row['Country']);
$temp[] = array('v' => (date) $row['synctime']);
$rows[] = array('c' => $temp);
}
$table['rows'] = $rows;
$jsonTable = json_encode($table);
이 시도
먼저 날짜 형식을 변환 한 다음 (날짜) 유형없이 배열에 전달하거나 문자열 유형을 정의 할 수 있습니다.
$getdate = date("Y-m-d H:i:s" , strtotime($row['synctime']));
$temp[] = array('v' => $getdate);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다