2015-04-23 46 views
-4

我有一個SELECT查詢:轉換陣列,並打印出用PHP

Array ([0] => Array ([id] => 1 [id_user] => 1 [id_category] => 1 [name] => Bambas futbol sala [description] => Bambas de futbol sala marca nike, color rojo y negro. Pie 43. [localization] => Barcelona [min_bid] => 25 [expiration] => 300 [terms] => - [highlights] => 0) [1] => Array ([id] => 2 [id_user] => 1 [id_category] => 6 [name] => Bateria electronica Roland td4 [description] => Vendo bateria electronida roland td4 kv versi�n 2009 por falta de tiempo. [localization] => Madrid [min_bid] => 600 [expiration] => 200 [terms] => - [highlights] => 0)) 

,我想它解析到這樣一個JSON(與我在陣列得到了各個領域)

"infos":[ [ { "id_user":"1", "id_category":"1", "name":"Bambas futbol sala", "description":"..." }, { "id_user":"2", "id_category":"3", "name":"Bambas futbol sala", "description":"..." } ] ], 

我該怎麼做,並用PHP打印?感謝

+2

你嘗試json_encode等json_decode? – Random

+0

我試過,但沒有工作.. –

回答

1

使用json_encodejson_decode

+0

是的,我試過,但這是行不通的.. –

+0

我有這個代碼,並總是這個回我: \t $ statement-> execute(); \t $ rawdata = array(); // $ creamos un array \t while($ row = $ statement-> fetch(PDO :: FETCH_ASSOC)){ \t $ rawdata [] = $ row; \t \t} \t print_r($ rawdata); \t echo「
json encode below:
」; \t echo json_encode($ rawdata,JSON_FORCE_OBJECT); –