Viewed   161 times

I have to get a table in my website. And have to get the data for this table from "http://west.basketball.nl/db/json/stand.pl?szn_Naam=2014-2015&cmp_ID=373" I've tried a lot of thing but nothing works....

 <!DOCTYPE html>
  <html>
   <head>
    <script type="text/javascript" 
       src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
   </head>
   <body>
    <?php
    $json=file_get_contents("http://west.basketball.nl/db/json
    /stand.pl?szn_Naam=2014-2015&cmp_ID=373");
            $data =  json_decode($json);

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

            // Cycle through the array
            foreach ($data as $stand) {

                // Output a row
                echo "<tr>";
                echo "<td>$afko</td>";
                echo "<td>$positie</td>";
                echo "</tr>";
            }

            // Close the table
            echo "</table>";
        }
    ?>
  </body>
</html>

 Answers

4

Ok first thing to do when getting data from an external source is to understand what is being returned.

So do

<?php
$json=file_get_contents("http://west.basketball.nl/db/json/stand.pl?szn_Naam=2014-2015&cmp_ID=373");
$data =  json_decode($json);

print_r($data);

Result:

stdClass Object
(
    [stand] => Array
        (
            [0] => stdClass Object
                (
                    [afko] => Risne Stars HS 1
                    [ID] => 2091
                    [status] => Actief
                    [gespeeld] => 3
                    [percentage] => 100.0
                    [punten] => 6
                    [tegenscore] => 149
                    [eigenscore] => 191
                    [datum] => 2014-10-05
                    [saldo] => 42
                    [team] => Risne Stars Heren 1
                    [positie] => 1
                )

            [1] => stdClass Object
                (
                    [afko] => D.B.V. Arriba HS 2
                    [ID] => 1813
                    [status] => Actief
                    [gespeeld] => 2
                    [percentage] => 0.0
                    [punten] => 0
                    [tegenscore] => 116
                    [eigenscore] => 102
                    [datum] => 2014-10-05
                    [saldo] => -14
                    [team] => D.B.V. Arriba Heren 2
                    [positie] => 10
                )

            [2] => stdClass Object
                (
                    [afko] => The Valley Bucketeers HS 2
                    [ID] => 2430
                    [status] => Actief
                    [gespeeld] => 2
                    [percentage] => 0.0
                    [punten] => 0
                    [tegenscore] => 177
                    [eigenscore] => 70
                    [datum] => 2014-10-05
                    [saldo] => -107
                    [team] => The Valley Bucketeers Heren 2
                    [positie] => 11
                )

            [3] => stdClass Object
                (
                    [afko] => Uitsmijters HS 2
                    [ID] => 2143
                    [status] => Actief
                    [gespeeld] => 2
                    [percentage] => 100.0
                    [punten] => 4
                    [tegenscore] => 79
                    [eigenscore] => 161
                    [datum] => 2014-10-05
                    [saldo] => 82
                    [team] => Uitsmijters Heren 2
                    [positie] => 2
                )

            [4] => stdClass Object
                (
                    [afko] => Picker Reds HS 1
                    [ID] => 2056
                    [status] => Actief
                    [gespeeld] => 3
                    [percentage] => 66.7
                    [punten] => 4
                    [tegenscore] => 193
                    [eigenscore] => 184
                    [datum] => 2014-10-05
                    [saldo] => -9
                    [team] => Picker Reds Heren 1
                    [positie] => 3
                )

            [5] => stdClass Object
                (
                    [afko] => Peatminers HS 2
                    [ID] => 6247
                    [status] => Actief
                    [gespeeld] => 1
                    [percentage] => 100.0
                    [punten] => 2
                    [tegenscore] => 36
                    [eigenscore] => 64
                    [datum] => 2014-10-05
                    [saldo] => 28
                    [team] => Peatminers Heren 2
                    [positie] => 4
                )

            [6] => stdClass Object
                (
                    [afko] => Jolly Jumpers HS 1
                    [ID] => 1994
                    [status] => Actief
                    [gespeeld] => 2
                    [percentage] => 50.0
                    [punten] => 2
                    [tegenscore] => 103
                    [eigenscore] => 119
                    [datum] => 2014-10-05
                    [saldo] => 16
                    [team] => Jolly Jumpers Heren 1
                    [positie] => 5
                )

            [7] => stdClass Object
                (
                    [afko] => TONEGO '65 HS 2
                    [ID] => 2120
                    [status] => Actief
                    [gespeeld] => 2
                    [percentage] => 50.0
                    [punten] => 2
                    [tegenscore] => 107
                    [eigenscore] => 122
                    [datum] => 2014-10-05
                    [saldo] => 15
                    [team] => TONEGO '65 Heren 2
                    [positie] => 6
                )

            [8] => stdClass Object
                (
                    [afko] => Amical HS 2
                    [ID] => 1791
                    [status] => Actief
                    [gespeeld] => 3
                    [percentage] => 33.3
                    [punten] => 2
                    [tegenscore] => 180
                    [eigenscore] => 195
                    [datum] => 2014-10-05
                    [saldo] => 15
                    [team] => Amical Heren 2
                    [positie] => 7
                )

            [9] => stdClass Object
                (
                    [afko] => S.V.Z.W. HS 2
                    [ID] => 5526
                    [status] => Actief
                    [gespeeld] => 3
                    [percentage] => 33.3
                    [punten] => 2
                    [tegenscore] => 174
                    [eigenscore] => 151
                    [datum] => 2014-10-05
                    [saldo] => -23
                    [team] => S.V.Z.W. Heren 2
                    [positie] => 8
                )

            [10] => stdClass Object
                (
                    [afko] => Twente Buzzards HS 3
                    [ID] => 2294
                    [status] => Actief
                    [gespeeld] => 3
                    [percentage] => 33.3
                    [punten] => 2
                    [tegenscore] => 196
                    [eigenscore] => 151
                    [datum] => 2014-10-05
                    [saldo] => -45
                    [team] => Twente Buzzards Heren 3
                    [positie] => 9
                )

        )

    [nummer] => OHS2C
    [version] => 1.0
    [aantal_teams] => 11
    [id] => 373
    [seizoen] => 2014-2015
    [naam] => Oost Afdeling Heren Senioren 2e klasse C
    [gewijzigd] => 2014-10-05 18:34:25
)

So now you know you are dealing with an OBJECT and not scalar values or an array.

So try this code:-

<?php
    $json=file_get_contents("http://west.basketball.nl/db/json/stand.pl?szn_Naam=2014-2015&cmp_ID=373");
    $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->afko</td>";
            echo "<td>$stand->positie</td>";
            echo "</tr>";
        }

        // Close the table
        echo "</table>";
    }
?>
Wednesday, August 10, 2022
3

You're not changing $info['photo'] inside the loop. That's why you're echoing the same photo five times.

Depending how your code looks like you can modify your code like this:

$result = mysql_query($your_query);

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
    echo("<td width="125" height="125"><img width="125" height="125" src=" images/". $row["photo"] ."></td>");
}
Monday, October 17, 2022
 
aren
 
1

I see some errors in your HTML.

I formatted your source locally. I dont know if you did this on purpose (just copy a small part of the table) but there are some tags missing.

I corrected your HTML, maybe you should try that. I dont know if it solves the problem. But here are some errors:

  • You never close the <b> tags in the first table row.
  • There is a table data tag (<td>) you do not close (And which is one too many) after Week 2 hours.
  • You do not close the table row tage for the first row. (<tr>)
  • You do not close the form tag.
  • The word form between the method and action in your opening form tag is incorrect. This should be removed i guess.

<html>

<form method="POST" action="result.php">
<table>
    <tr>
        <td><b>Day of Week</b></td>
        <td><b>Week 1 Hours</b></td>
        <td><b>Week 2 Hours</b></td>
    </tr>
    <tr>
        <td>Monday</td>
        <td><input type="text" name="Monday" size="3" maxlength="4" value="" onkeypress="return inputLimiter(event,'Numbers')"> <input type="checkbox" tabindex="-1" name="Stime1">Sick?<input type="checkbox" tabindex="-1" name="Vac1">Vacation?</td>
        <td><input type="text" name="Monday2" size="3" maxlength="4" value="" onkeypress="return inputLimiter(event,'Numbers')"> <input type="checkbox" tabindex="-1" name="Stime2">Sick?<input type="checkbox" tabindex="-1" name="Vac2">Vacation?</td>
    </tr>
</table>
<input type="submit" value="submit">
</form>
</html>

Let me know if this helps. Cheers.

Thursday, October 6, 2022
 
4

In the Azure Function your first you need to add a reference to NewtonSoft.JSON. You can do this via "Newtonsoft.Json". Do not forget the quotes!!!

Than you can use the normal serialization via newtonsoft:

var response = await client.GetAsync("<url>");
var json = await response.Content.ReadAsStringAsync();
var o= JsonConvert.DeserializeObject<"Type">(json);
Tuesday, September 13, 2022
4

Run your JSON through a JSON validator, for instance JSONLint.com. You have a syntax error in your JSON:

{
    "length": 2,
    "info": [
        {
            "fullname":"Noob Here",
            "email":"myemail@server.com",
            "phone":"123456",
            "badgeid": "11111",  <---- Do not put a comma before a curly brace
        },
        {
            "fullname":"Newbie There",
            "email":"hisemail@server.com",
            "phone":"589433",
            "badgeid": "11112",  <---- remove comma before curly brace
        }
    ]
}

Your JSON should instead look like this:

{
    "length": 2,
    "info": [
        {
            "fullname":"Noob Here",
            "email":"myemail@server.com",
            "phone":"123456",
            "badgeid": "11111"
        },
        {
            "fullname":"Newbie There",
            "email":"hisemail@server.com",
            "phone":"589433",
            "badgeid": "11112"
        }
    ]
}
Sunday, December 4, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :