加入两个数据字段

时间:2013-05-29 15:18:59

标签: php arrays json getjson

$datax包含数字12(请参阅json输出),但必须包含类似于1 / XXX2 / XXX的条目等等($datax[] = $row['solution_id'] + " / " + $row['Type'];

错误在哪里?

<?php
include_once 'include/connect_db.php';

$query="SELECT A.solution_id, A.Type,A.Time2,B.Time1 
           FROM Table1 A 
           INNER JOIN Table2 B 
           ON A.Type=B.Type;";

$result=ejecutar_query($query);

$datax = array();
$datay1 = array();
$datay2 = array();

while($row=mysql_fetch_assoc($result)) {
    $datax[] = $row['solution_id'] + " / " + $row['Type'];
    $datay1[] = $row['Time1'];
    $datay2[] = $row['Time2'];
}

echo json_encode(array('x' => $datax, 'y1' => $datay1, 'y2' => $datay2));
die();

?>

JSON

  

{“x”:[1,2,1,2,1,2,1,2,1,2,1,2],“y1”:[“2013-05-29 17:24:00 “” 2013年5月29日   17:24:00“,”2013-05-29 17:22:00“,”2013-05-29 17:22:00“,”2013-05-29   17:18:00“,”2013-05-29 17:18:00“,”2013-05-29 17:16:00“,”2013-05-29   17:16:00“,”2013-05-29 17:11:00“,”2013-05-29 17:11:00“,”2013-05-29   17:11:00“,”2013-05-29 17:11:00“],”y2“:[”2013-05-29   17:56:26“,”2013-05-29 18:03:38“,”2013-05-29 17:48:12“,”2013-05-29   17:42:53“,”2013-05-29 17:10:32“,”2013-05-29 17:52:08“,”2013-05-29   17:08:00“,”2013-05-29 17:10:18“,”2013-05-29 17:42:53“,”2013-05-29   17:06:12“,”2013-05-29 17:05:39“,”2013-05-29 18:09:00“]}

2 个答案:

答案 0 :(得分:2)

在PHP中,.是连接运算符

while($row=mysql_fetch_assoc($result)) {
    $datax[] = $row['solution_id'] . " / " . $row['Type'];
    $datay1[] = $row['Time1'];
    $datay2[] = $row['Time2'];
}

http://php.net/manual/en/language.operators.string.php

答案 1 :(得分:1)

你必须在php中使用点运算符.。所以$row['solution_id'] . " / " . $row['Type']会有所帮助。