I just started to learn PHP and I have managed to get JSON data back that I need but struggling to build a table from the JSON data. I know I am doing it totally wrong with trial and error, but stuck now.
The PHP I have so far:
<?php
............
$domains = json_decode(get_option('cc_whmcs_bridge_tlds'), true);
if (count($domains->pricing)) {
// Open the table
echo "<table>";
// Cycle through the array
foreach ($domains->pricing as $idx => $tld) {
// Output a row
echo "<tr>";
echo "<td>$tld->register[$idx]</td>";
echo "<td>$tld->transfer->[$idx]</td>";
echo "</tr>";
}
// Close the table
echo "</table>";
}
?>
JSON OUTPUT EXAMPLE
{
"currency": {
"id": "1",
"code": "USD",
"prefix": "$",
"suffix": " USD",
"format": "2",
"rate": "1.00000"
},
"pricing": {
"com": {
"categories": [
"Popular",
"gTLD"
],
"addons": {
"dns": true,
"email": true,
"idprotect": true
},
"group": "new",
"register": {
"1": "9.95",
"2": "19.90",
"3": "29.85"
},
"transfer": {
"1": "9.95",
"2": "15.00",
"3": "25.00"
},
"renew": {
"1": "9.95",
"2": "15.00",
"3": "25.00"
}
},
"net": {
"categories": [
"Popular",
"gTLD"
],
"addons": {
"dns": false,
"email": false,
"idprotect": false
},
"group": "sale",
"register": {
"1": "9.00"
},
"transfer": {
"1": "11.95"
},
"renew": {
"1": "11.95"
}
},
"org": {
"categories": [
"Popular",
"gTLD"
],
"addons": {
"dns": false,
"email": false,
"idprotect": false
},
"group": "hot",
"register": {
"1": "11.95"
},
"transfer": {
"1": "11.95"
},
"renew": {
"1": "11.95"
}
}
}
}
I know I have got the table PHP stuff totally wrong but as I said, first time for me so that is as far as I got.
The table I am trying to render would be something like:
TLD | REGISTER | TRANSFER | RENEW
---------------------------------------------
.com | 1yr (9.95) | 1yr (9.95) | 1yr (9.95)
.co.uk | 1yr (9.95) | 1yr (9.95) | 1yr (9.95)
etc....