[wpseo_breadcrumb]

Trying to display Json data from a web url into a table

Solutons:


You can take this json and put it in the loop through length of the json and show data into the table.

This is how i solved it

<?php
            try{
                $url="the json url goes here"; // path to your JSON file
                $data = file_get_contents($url); // put the contents of the file into a variable
                $characters = json_decode($data);
                echo '<div class="panel-heading">
            <h3 align="center">Market Prices for ';  echo $characters[0]->Crop;
                echo '</h3>
        </div>';
                echo '<div class="panel-body">
            <table class="table table-striped table-hover border" style="font-family: cambria">
                <thead>
                <tr>
                    <th>Market</th>
                    <th>Date</th>
                    <th>Price</th>
                </tr>
                </thead>
                <tbody>';
                foreach ($characters as $character) {
                    echo '<tr>';
                    echo '<td>' . $character->Market . '</td>';
                    echo '<td>' . $character->Date . '</td>';
                    echo '<td>' . $character->Price . '</td>';
                    echo '</tr>';
                }

                echo '</tbody>
        </table>
    </div>';
            }
            catch (Exception $e){
                echo '<p align="center">No Internet Connection, please try again</p>';
            }
            ?>

Related Solutions

What does __all__ mean in Python?

Linked to, but not explicitly mentioned here, is exactly when __all__ is used. It is a list of strings defining what symbols in a module will be exported when from <module> import * is used on the module. For example, the following code in a foo.py...

Is the linux kernel ported to JavaScript yet?

Javascript is not a systems programming language, it is not appropriate for a kernel. Additionally, the kernel is a very large body of code, and "porting" it to another language is not something that can be done easily, and would likely take years. If the...

How to insert (file) data into a PostgreSQL bytea column?

as superuser: create or replace function bytea_import(p_path text, p_result out bytea) language plpgsql as $$ declare l_oid oid; begin select lo_import(p_path) into l_oid; select lo_get(l_oid) INTO p_result; perform lo_unlink(l_oid); end;$$; lo_get was...

What is the best color combination for on screen reading?

Legibility depends on high contrast between foreground and background, so black-and-white is the safest bet. See for example: Hall RH & Hanna H 2003. The Impact of Web Page Text-Background Color Combinations on Readability, Retention, Aesthetics, and...

MATCH FULL vs MATCH SIMPLE in foreign key constraints

Check the CREATE TABLE page of the manual: There are three match types: MATCH FULL, MATCH PARTIAL, and MATCH SIMPLE (which is the default). MATCH FULL will not allow one column of a multicolumn foreign key to be null unless all foreign key columns are null; if...

JavaScript set object key by variable

You need to make the object first, then use [] to set it. var key = "happyCount"; var obj = {}; obj[key] = someValueArray; myArray.push(obj); UPDATE 2021: Computed property names feature was introduced in ECMAScript 2015 (ES6) that allows you to dynamically...

What is the difference between const and readonly in C#?

Apart from the apparent difference of having to declare the value at the time of a definition for a const VS readonly values can be computed dynamically but need to be assigned before the constructor exits. After that it is frozen. const's are implicitly...

How should I index a UUID in Postgres?

Use PostgreSQL's built-in uuid data type, and create a regular b-tree index on it. There is no need to do anything special. This will result in an optimal index, and will also store the uuid field in as compact a form as is currently practical. (Hash indexes in...

Top level domain/domain suffix for private network?

Since the previous answers to this question were written, there have been a couple of RFCs that alter the guidance somewhat. RFC 6761 discusses special-use domain names without providing specific guidance for private networks. RFC 6762 still recommends not...

Getting last modification date of a PostgreSQL database table

There is no reliable, authorative record of the last modified time of a table. Using the relfilenode is wrong for a lot of reasons: Writes are initially recorded to the write-head log (WAL), then lazily to the heap (the table files). Once the record is in WAL,...

How do I make this sed script a “one liner”?

An ANSI C string -- with $'' -- can contain backslash escapes, like \n -- so you can have a newline in sed's arguments while still having the shell command invoking sed be only one line. sed -i $'/INTERPRETER_PYTHON_DISTRO_MAP/,/version_added/ {\n /default/a\\...

How to OCR a PDF file and get the text stored within the PDF?

ocrmypdf does a good job and can be used like this: ocrmypdf in.pdf out.pdf To install: pip install ocrmypdf or sudo apt install ocrmypdf # ubuntu sudo dnf -y install ocrmypdf # fedora After learning that Tesseract can now also produce searchable PDFs, I found...

If …Else If wont work [closed]

First of all, put the javascript code between a <script></script> tag because javascript code will not run in an html <div></div> tag. Then, instead of x == 0||9||2, use x == 0 || x == 9 || x == 2. Kindly indent your code for easier...

How to convert the object of character to string

Your object of characters is already almost an array. It has numeric indices, but is missing the .length property. If you add that it, it will be an "array like" object, which can then be passed to Array.from to get a proper array. Once you have a real array,...

How can I write the approximate value of PI?

Because your { and } is wrong. I think brackets will be as given below If the formula is PI = 4/1 - 4/3 + 4/5 - 4/7 + ... ( Leibniz's Series ) then you can formalate as given below #include <iostream> using namespace std; int main() { double n, i; //...