Mirko Mukaetov
Mirko Mukaetov

Reputation: 37

JSON TO HTML ROW USING PHP

I need to convert JSON into a list using PHP, Tried code below but cannot make it work

$json=file_get_contents("http://feeds.mse.mk/service/FreeMSEFeeds.svc/ticker/JSON/8BA941D0-D6E6-44BD-8D8B-47FDB7A563FA");
    $data =  json_decode($json);

    if (count($data->stand)) {
        // Open the table
        echo "<table>";

        // Cycle through the array
        foreach ($data->stand as $idx => $stand) {

            // Output a row
            echo "<tr>";
            echo "<td>$stand->AvgPrice</td>";
            echo "<td>$stand->Description </td>";
            echo "</tr>";
        }

        // Close the table
        echo "</table>";
    }

And I want to show list as here (not as a table):

http://prntscr.com/no1479

Upvotes: 0

Views: 43

Answers (2)

Kamlesh Jain
Kamlesh Jain

Reputation: 68

your all code is right but you can use stand class that is wrong your class is GetTickerJSONResult and so change the class stand to GetTickerJSONResult.

try this modified code..

 <?PHP
     $set =json_decode($json);
      if (count($set->GetTickerJSONResult)) {
       echo "<table>";
       foreach ($set->GetTickerJSONResult as $idx => $stand) {

          echo "<tr>";
          echo "<td>$stand->AvgPrice</td>";
          echo "<td>$stand->Description </td>";
          echo "</tr>";
       }
        echo "</table>";
   }
  ?>

Upvotes: 1

Ezequiel Esnaola
Ezequiel Esnaola

Reputation: 60

It does not work because in $data->stand there is nothing.

Upvotes: 0

Related Questions