0

$datax包含数字12(见json输出),但是它必须包含类似于1 / XXX,2 / 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-05-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"]}

4

2 回答 2

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

于 2013-05-29T15:22:12.780 回答
1

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

于 2013-05-29T15:24:19.950 回答