0

My issue is I don't know how to display this data into a table in php. When I try to pass only one variable $obj->message; I get trying to get non object. Can someone tell me how to display all of it in an html table?

My code:

<?php
$url = "http://api.vateud.net/notams/EPDE.json";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 4);
$json = curl_exec($ch);
if(!$json) {
    echo curl_error($ch);
}
curl_close($ch);
$obj= json_decode($json);
print_r($obj);
?>

and result:

Array
(
    [0] => stdClass Object
        (
            [raw] => B0552/17 NOTAMR B0372/17
Q) EPWW/QPIAU/I /NBO/A /000/999/5133N02154E005
A) EPDE B) 1701201151 C) 1701301430
E) INSTRUMENT APPROACH PROCEDURES:
- ILS OR LOC RWY30 (CAT A/B/C/D/E) NOT AVBL.

            [message] => INSTRUMENT APPROACH PROCEDURES:
- ILS OR LOC RWY30 (CAT A/B/C/D/E) NOT AVBL.

            [icao] => EPDE
        )

    [1] => stdClass Object
        (
            [raw] => B0551/17 NOTAMR B0371/17
Q) EPWW/QICAS/I /NBO/A /000/999/5133N02154E005
A) EPDE B) 1701201151 C) 1701301430
E) ILS AND DME IDN CH28X U/S.

            [message] => ILS AND DME IDN CH28X U/S.

            [icao] => EPDE
        )

    [2] => stdClass Object
        (
            [raw] => B0546/17 NOTAMR B7851/16
Q) EPWW/QSAAS/IV/BO /A /000/999/5133N02154E005
A) EPDE B) 1701200946 C) 1702222100
E) ATIS ON TEST. DO NOT USE.

            [message] => ATIS ON TEST. DO NOT USE.

            [icao] => EPDE
        )

    [3] => stdClass Object
        (
            [raw] => B7983/16 NOTAMN
Q) EPWW/QMNLT/IV/NBO/A /000/999/5133N02154E005
A) EPDE B) 1612230741 C) 1703230700
E) APN A - NOT AVBL WEST PART OF APRON, 
DIMENSIONS: LENGHT 362M, WIDTH 77M.

            [message] => APN A - NOT AVBL WEST PART OF APRON, 
DIMENSIONS: LENGHT 362M, WIDTH 77M.

            [icao] => EPDE
        )

    [4] => stdClass Object
        (
            [raw] => B7982/16 NOTAMR B6578/16
Q) EPWW/QFALT/IV/NBO/A /000/999/5133N02154E005
A) EPDE B) 1612230739 C) 1703230700
E) AERODROME AVBL FOR AKADEMICKI OSRODEK SZKOLENIA LOTNICZEGO AND
AEROKLUB ORLAT:
FRI 2100- MON 0430,
MON-FRI 2100-0430.

            [message] => AERODROME AVBL FOR AKADEMICKI OSRODEK SZKOLENIA LOTNICZEGO AND
AEROKLUB ORLAT:
FRI 2100- MON 0430,
MON-FRI 2100-0430.

            [icao] => EPDE
        )

    [5] => stdClass Object
        (
            [raw] => B6826/16 NOTAMR B4965/16
Q) EPWW/QMXLC/IV/M  /A /000/999/5133N02154E005
A) EPDE B) 1611160841 C) 1702152100
E) TWY A NEAR APRON A CLSD.

            [message] => TWY A NEAR APRON A CLSD.

            [icao] => EPDE
        )

    [6] => stdClass Object
        (
            [raw] => B6631/16 NOTAMR B6606/16
Q) EPWW/QFMLT/IV/BO /A /000/999/5133N02154E005
A) EPDE B) 1611070909 C) 1701310430
E) 1.MIL MET OFFICE HOURS OF SERVICES:
-  MON 0430 - FRI 2100.
-  THE WORKING DAYS BEFORE HOLIDAYS TILL 2100.
-  THE WORKING DAYS AFTER  HOLIDAYS FROM 0430.
-  SAT, SUN AND NOV 11, DEC 26, JAN 01, JAN 06 CLOSED.
2. MET INFORMATION ON HOLIDAYS AVBL PPR 24HR.
3. MET MEASUREMENT AND OBSERVATIONS ARE PERFORMED EVERY DAY
   FROM 0230 TILL 2100 EVERY 30 MINUTES. SOME OTHER TIME AVAILABLE
   METAR AUTO ONLY.

            [message] => 1.MIL MET OFFICE HOURS OF SERVICES:
-  MON 0430 - FRI 2100.
-  THE WORKING DAYS BEFORE HOLIDAYS TILL 2100.
-  THE WORKING DAYS AFTER  HOLIDAYS FROM 0430.
-  SAT, SUN AND NOV 11, DEC 26, JAN 01, JAN 06 CLOSED.
2. MET INFORMATION ON HOLIDAYS AVBL PPR 24HR.
3. MET MEASUREMENT AND OBSERVATIONS ARE PERFORMED EVERY DAY
   FROM 0230 TILL 2100 EVERY 30 MINUTES. SOME OTHER TIME AVAILABLE
   METAR AUTO ONLY.

            [icao] => EPDE
        )

    [7] => stdClass Object
        (
            [raw] => B6595/16 NOTAMR B5280/16
Q) EPWW/QFULT/IV/NBO/A /000/999/5133N02154E005
A) EPDE B) 1611040838 C) 1702032100
E) RESTRICTIONS FOR ACFT NOT BASED ON AERODROME:
FUEL AVBL PPR 72HR ONLY .

            [message] => RESTRICTIONS FOR ACFT NOT BASED ON AERODROME:
FUEL AVBL PPR 72HR ONLY .

            [icao] => EPDE
        )

)
Jason
  • 3,330
  • 1
  • 33
  • 38
tomczas
  • 179
  • 1
  • 4
  • 20

1 Answers1

0

someone tell me how to display all of it in html table?

Given the fact that you're getting decoded array using $obj= json_decode($json);, the solution would be to use the following table structure and the subsequent nested foreach loops like this:

echo '<table>';
    echo '<tr>';
        echo '<th>raw</th>';
        echo '<th>message</th>';
        echo '<th>icao</th>';
    echo '</tr>';

    foreach($obj as $o){
        echo '<tr>';
        foreach($o as $value){
            echo '<td>' . $value . '</td>';
        }
        echo '</tr>';
    }
echo '</table>'; 
Rajdeep Paul
  • 16,887
  • 3
  • 18
  • 37
  • and tell me how to display it as an body for example : raw, message,icao and under that second raw, message, icao – tomczas Jan 22 '17 at 20:07
  • @tomczas Can you please elaborate what's your *expected* output? – Rajdeep Paul Jan 22 '17 at 20:14
  • so for example ICAO as title under it message and under it raw – tomczas Jan 22 '17 at 20:41
  • so for example ICAO as title under it message and under it raw – tomczas Jan 22 '17 at 20:54
  • @tomczas I've updated my answer. Please see the **Update(1)** section of my answer. – Rajdeep Paul Jan 22 '17 at 21:03
  • No no, not like this. Because it's still table. Now i want to display it like this B0552/17 NOTAMR B0372/17 Q) EPWW/QPIAU/I /NBO/A /000/999/5133N02154E005 A) EPDE B) 1701201151 C) 1701301430 E) INSTRUMENT APPROACH PROCEDURES: - ILS OR LOC RWY30 (CAT A/B/C/D/E) NOT AVBL.INSTRUMENT APPROACH PROCEDURES: - ILS OR LOC RWY30 (CAT A/B/C/D/E) NOT AVBL. EPDE and then second notam under it . So 1 array object under it second etc etc – tomczas Jan 22 '17 at 21:08
  • @tomczas Please use [pastebin.com](http://pastebin.com/index.php) and give me a sample layout of what you're trying to achieve. – Rajdeep Paul Jan 22 '17 at 21:13
  • I want to display it like this : http://pastebin.com/7GTihQsm i added "//" as comments – tomczas Jan 22 '17 at 21:27
  • @tomczas Please test your application with this code snippet, [http://pastebin.com/grLeBXf6](http://pastebin.com/grLeBXf6). See if that's the kind of layout you want. Later, you can modify the code snippet using proper `div`s, `margin`s and `padding`s. – Rajdeep Paul Jan 22 '17 at 21:40
  • ok and tell me if there any posiibility to fetch lines from that "message"? for example i want to fetch only Q and A section : Q) EPWW/QPIAU/I /NBO/A /000/999/5133N02154E005 A) EPDE and give them blue color. – tomczas Jan 22 '17 at 21:44
  • @tomczas You requirement is completely different from what you asked in your question. You need to use PHP regex to extract relevant data from your *message*s, you can start with this: http://stackoverflow.com/questions/4736/learning-regular-expressions – Rajdeep Paul Jan 22 '17 at 21:52
  • This script which u give me is perfect for me ;) so thank u . Second question was out of topic , just to my knowledge ;) – tomczas Jan 22 '17 at 22:00