What on earth is wrong with my code????

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Irontiga
Forum Newbie
Posts: 4
Joined: Fri Oct 03, 2014 4:16 pm

What on earth is wrong with my code????

Post by Irontiga »

OK, making an api call with when acc=BURST-KHTJ-G3H7-LD2Q-H7LJ6.

This is the first array coming from

Code: Select all

json_decode(file_get_contents("http://127.0.0.1:8125/burst?requestType=getAccount&account=".$_GET['acc']))

Code: Select all

{
"publicKey": "231add65e7233e8df06debe3e71f161cb8975d21c9f9ee6e52f4868f524cb64d",
"assetBalances": [
    {
        "asset": "15295227971848272658",
        "balanceQNT": "4205"
    },
    {
        "asset": "11375670541237055652",
        "balanceQNT": "15"
    }
],
"guaranteedBalanceNQT": "0",
"balanceNQT": "5465615075791",
"name": "Irontiga",
"accountRS": "BURST-KHTJ-G3H7-LD2Q-H7LJ6",
"unconfirmedAssetBalances": [
    {
        "unconfirmedBalanceQNT": "4205",
        "asset": "15295227971848272658"
    },
    {
        "unconfirmedBalanceQNT": "15",
        "asset": "11375670541237055652"
    }
],
"account": "17456591454562991920",
"effectiveBalanceNXT": 0,
"unconfirmedBalanceNQT": "4870615075791",
"forgedBalanceNQT": "0"
}
and then the array from

Code: Select all

json_decode(file_get_contents("http://127.0.0.1:8125/burst?requestType=getAsset&asset=".$assetID))

Code: Select all

{
"decimals": 1,
"numberOfTrades": 58,
"asset": "15295227971848272658",
"quantityQNT": "1000000",
"description": "Shares in BURST pool. See https://burstforum.com/index.php?threads/the-big-announcement.149/ for more details",
"name": "HardInvest",
"accountRS": "BURST-T7BK-USTG-KVKC-D2RDL",
"account": "13343849956527346993"
}
My code looks like this

Code: Select all

<!DOCTYPE html>
<html>
<head>

</head>
<body>

<?php
    $account = json_decode(file_get_contents("http://127.0.0.1:8125/burst?requestType=getAccount&account=".$_GET['acc']));
    echo $account->name;
    foreach($account->assetBalances as $assetBalance)
    {
        assetID = $assetBalance['asset'];
        $assetInfo = json_decode(file_get_contents("http://127.0.0.1:8125/burst?requestType=getAsset&asset=".$assetID));
        echo $assetInfo['description'];
        echo "<br>";
    }

?>
</body>
</html>
But just isn't working, why not? All it does is load really quickly and not display anything.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: What on earth is wrong with my code????

Post by requinix »

$assetBalance and $assetInfo are objects, not arrays. Just like $account.
Irontiga
Forum Newbie
Posts: 4
Joined: Fri Oct 03, 2014 4:16 pm

Re: What on earth is wrong with my code????

Post by Irontiga »

requinix wrote:$assetBalance and $assetInfo are objects, not arrays. Just like $account.
So how do I fix?

This doeesn't work

Code: Select all

assetID = $assetBalance->asset;

echo $assetInfo->name;
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: What on earth is wrong with my code????

Post by Celauran »

Irontiga wrote:This doesn't work
That's a bit vague...
Irontiga wrote:

Code: Select all

assetID = $assetBalance->asset;
Variables in PHP start with $
Irontiga
Forum Newbie
Posts: 4
Joined: Fri Oct 03, 2014 4:16 pm

Re: What on earth is wrong with my code????

Post by Irontiga »

Celauran wrote:
Irontiga wrote:This doesn't work
That's a bit vague...
Irontiga wrote:

Code: Select all

assetID = $assetBalance->asset;
Variables in PHP start with $

THANKS!!!!

That was the problem.
Irontiga
Forum Newbie
Posts: 4
Joined: Fri Oct 03, 2014 4:16 pm

Re: What on earth is wrong with my code????

Post by Irontiga »

1 more thing, how can I access ONLY the first element in an array without using foreach?

DW, got it.
borre
Forum Newbie
Posts: 10
Joined: Thu Oct 02, 2014 7:21 am

Re: What on earth is wrong with my code????

Post by borre »

How did you do it?

Because PHP has a nice function for that, called: current( $array );

As long as you didn't run trough your array you can use this function to get the current KEY of the array you specify.
Post Reply