创建json格式

时间:2015-09-22 18:31:53

标签: php mysql json

我使用查询(Union)从许多表创建了json格式。但是我只得到一个json结果而不是三个结果。结果是

["Used","Huawei","Samsung","Mandalay"]

所以,我想在"使用"前面插入名字。像那样["条件":"使用"]。 我怎么能这样做?

这是我的代码

<?php
    $result=mysql_query(" SELECT ttd.name 
                      FROM   `taxonomy_term_data` AS ttd
                      INNER JOIN `field_data_field_ph_condition` AS fdc
                      ON   fdc.field_ph_condition_tid=ttd.tid
                      INNER JOIN `node` AS N
                      ON n.nid=fdc.entity_id 
                      UNION
                      SELECT ttd.name 
                      FROM   `taxonomy_term_data` AS ttd
                      INNER JOIN `field_data_field_brand` AS fb
                      ON   fb.field_brand_tid=ttd.tid
                      INNER JOIN `node` AS N
                      ON n.nid=fb.entity_id 
                      UNION
                      SELECT ttd.name 
                      FROM   `taxonomy_term_data` AS ttd
                      INNER JOIN `field_data_field_city` AS fb
                      ON   fb.field_city_tid=ttd.tid
                      INNER JOIN `node` AS N
                      ON n.nid=fb.entity_id 
                      ") or die(mysql_error());

 while ($row = mysql_fetch_array( $result, MYSQL_ASSOC)) {
 $json_response[] = $row['name'];
}
  echo json_encode($json_response); 
?>

0 个答案:

没有答案