2016-11-18 8 views
0

私はGoogle API Chartを使用しているプロジェクトに取り組んでおり、phpを使ってデータを取得してテーブルチャートを作成しています(& json)。今私はエラーを与えるmysqlのデータベースにタイムスタンプのデータ型を使用している 'synctime'の列に固執しています。私は「日付」の代わりに何を使用すべきですか?PHP/MySQLでJSONのGoogle Chartにタイムスタンプを使用する方法

ご協力いただきありがとうございます。私のコードは以下の通りです:

$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); 
+0

'日付(「はYmd」、$行[「SYNCTIME」])'または任意の形式のコードは私のために動作しませんでしたが、あなたが、助けのための –

+0

こんにちは@AlexTartanの感謝を必要とするが、これは私を与えますアイデア。 –

答えて

0

あなたの日付形式を変換し、(日付)せずに、配列に渡す入力するか、文字列型を定義することができ、この

ファーストをお試しください。

$getdate = date("Y-m-d H:i:s" , strtotime($row['synctime'])); 
$temp[] = array('v' => $getdate); 
+0

それは私のために働いてくれてありがとう。 $ temp [] = array( 'v' => date( "Y-m-d H:i:s"、strtotime($ row ['synctime']))); ' –

関連する問題