Welcome Guest, Not a member yet? Register   Sign In
JSON Decode Array
#1

[eluser]Unknown[/eluser]
Hello everyone, i newbie on code igniter, i have json data like this, how to i'm parsing in code igniter and output to table ?

Thank you for your help.

Code:
stdClass Object
(
    [output_type] => json
    [round_trip] => 1
    [search_queries] => stdClass Object
        (
            [from] => CGK
            [to] => SUB
            [date] => 2012-12-28
            [ret_date] =>
            [adult] => 2
            [child] => 0
            [infant] => 0
            [sort] =>
        )

    [go_det] => stdClass Object
        (
            [dep_airport] => stdClass Object
                (
                    [airport_code] => CGK
                    [international] => 1
                    [trans_name_id] => 7574
                    [business_name] => Soekarno-Hatta
                    [business_name_trans_id] => 5935
                    [business_id] => 20361
                    [country_name] => Indonesia
                    [city_name] => Jakarta Barat
                    [province_name] => DKI Jakarta
                    [location_name] => Jakarta
                )

            [arr_airport] => stdClass Object
                (
                    [airport_code] => SUB
                    [international] => 1
                    [trans_name_id] => 7595
                    [business_name] => Juanda
                    [business_name_trans_id] => 5963
                    [business_id] => 20389
                    [country_name] => Indonesia
                    [city_name] => Surabaya
                    [province_name] => Jawa Timur
                    [location_name] => Surabaya
                )

            [date] => 2012-12-28
            [formatted_date] => 28 Desember 2012
        )

    
    [diagnostic] => stdClass Object
        (
            [status] => 200
            [elapsetime] => 1.2492
            [memoryusage] => 17.59MB
            [confirm] => success
            [lang] => id
            [currency] => IDR
        )

    [departures] => stdClass Object
        (
            [result] => Array
                (
                    [0] => stdClass Object
                        (
                            [flight_id] => 1435266
                            [airlines_name] => GARUDA
                            [flight_number] => GA-314
                            [price_value] => 1919600.00
                            [timestamp] => 2012-12-20 09:30:49
                            [price_adult] => 959800.00
                            [price_child] => 0.00
                            [price_infant] => 0.00
                            [simple_departure_time] => 12:20
                            [simple_arrival_time] => 13:50
                            [stop] => Langsung
                            [long_via] =>
                            [duration] => 1 j 30 m
                            [image] => https://www.master18.tiket.com/images/tiket2/icon_garuda_2.jpg
                        )

                    [1] => stdClass Object
                        (
                            [flight_id] => 1435265
                            [airlines_name] => GARUDA
                            [flight_number] => GA-312
                            [price_value] => 1919600.00
                            [timestamp] => 2012-12-20 09:30:49
                            [price_adult] => 959800.00
                            [price_child] => 0.00
                            [price_infant] => 0.00
                            [simple_departure_time] => 11:10
                            [simple_arrival_time] => 12:40
                            [stop] => Langsung
                            [long_via] =>
                            [duration] => 1 j 30 m
                            [image] => https://www.master18.tiket.com/images/tiket2/icon_garuda_2.jpg
                        )

                    [2] => stdClass Object
                        (
                            [flight_id] => 1435267
                            [airlines_name] => GARUDA
                            [flight_number] => GA-316
                            [price_value] => 1919600.00
                            [timestamp] => 2012-12-20 09:30:49
                            [price_adult] => 959800.00
                            [price_child] => 0.00
                            [price_infant] => 0.00
                            [simple_departure_time] => 13:50
                            [simple_arrival_time] => 15:20
                            [stop] => Langsung
                            [long_via] =>
                            [duration] => 1 j 30 m
                            [image] => https://www.master18.tiket.com/images/tiket2/icon_garuda_2.jpg
                        )

                )

        )

    [token] => d56145sd4d59f5404e5d42db55f1a099f79
)
#2

[eluser]pickupman[/eluser]
Assuming a variable $json holds the object you posted, you should be able to create a table as such.
Code:
<table>

&lt;?php foreach ($json->departures->result as $departure) { ?&gt;
    <tr>
        <td>&lt;?php echo $departure['flight_id'];?&gt;</td>
        <td>&lt;?php echo $departure['airlines_name'];?&gt;</td>
        <td><img src="&lt;?php echo $departure['image'];?&gt;"/></td>
    </tr>
&lt;?php } ?&gt;

</table>
#3

[eluser]Unknown[/eluser]
Very Thank You It's Work.

[quote author="pickupman" date="1356537700"]Assuming a variable $json holds the object you posted, you should be able to create a table as such.
Code:
<table>

&lt;?php foreach ($json->departures->result as $departure) { ?&gt;
    <tr>
        <td>&lt;?php echo $departure['flight_id'];?&gt;</td>
        <td>&lt;?php echo $departure['airlines_name'];?&gt;</td>
        <td><img src="&lt;?php echo $departure['image'];?&gt;"/></td>
    </tr>
&lt;?php } ?&gt;

</table>
[/quote]
#4

[eluser]CroNiX[/eluser]
As a side, It usually looks much cleaner if you use the php alternative control structures when using HTML in your views. It also helps a lot of IDEs recognize the HTML as HTML since it's not within a PHP code block (between curly braces)

Code:
<table>
&lt;?php foreach ($json->departures->result as $departure): //colon here instead of brace ?&gt;
    <tr>
        <td>&lt;?php echo $departure['flight_id'];?&gt;</td>
        <td>&lt;?php echo $departure['airlines_name'];?&gt;</td>
        <td><img src="&lt;?php echo $departure['image'];?&gt;"/></td>
    </tr>
&lt;?php endforeach; //endforeach statement here instead of end curly brace?&gt;
</table>

http://ellislab.com/codeigniter/user-gui...e_php.html




Theme © iAndrew 2016 - Forum software by © MyBB