Bitcoin Forum
May 20, 2024, 10:48:05 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Warning: One or more bitcointalk.org users have reported that they strongly believe that the creator of this topic is a scammer. (Login to see the detailed trust ratings.) While the bitcointalk.org administration does not verify such claims, you should proceed with extreme caution.
Pages: [1]
  Print  
Author Topic: Blockchain.info PHP Parse  (Read 704 times)
michaeladair (OP)
Sr. Member
****
Offline Offline

Activity: 448
Merit: 250


I'm a Web Developer: HTML, CSS, PHP, JS.


View Profile
January 08, 2015, 05:11:53 AM
Last edit: January 08, 2015, 05:41:45 AM by michaeladair
 #1

SOLVED

I need help with some JSON Parsing using PHP...
I'll show you the code first then tell you where my problem lies.
Code:
<?php 
$address "1CaiKQcVSF2hY5sHgtirfK5ytLSZHXkxB2";
        
$ch curl_init(); 

        
curl_setopt($chCURLOPT_RETURNTRANSFERTRUE);
        
curl_setopt($chCURLOPT_URL"https://blockchain.info/address/$address?filter=1&format=json");

        
$output curl_exec($ch); 

        
curl_close($ch);      

        
$a=json_decode($output,TRUE);
?>

<table class="table table-bordered">
    <tr>
        <th>
            #
        </th>
        <th>
            Date Sent
        </th>
        <th>
            Address(es)
        </th>
        <th>
            Amount Sent
        </th>
    </tr>
<?php $counter=1?>
<?php if (is_array($a["txs"])) { ?>
    <?php foreach ($a["txs"] as $tx) { ?>
        <tr>
            <td>
                <?php print_r($counter++); ?>
            </td>
            <td>
                <?php print_r(date("Y-m-d",$tx["time"])); ?>
            </td>
            <td>
                <?php print_r($tx["out"][0]["addr"]); ?>
            </td>
            <td>
<?php $inputs = $tx["inputs"][0]["prev_out"]; $value=0;
foreach($inputs as $num=>$inDetails){
     if($inDetails["addr"]==$address){
         $value=$inDetails["value"];
     }
}
?>

                <?php print_r(round($value/1000000004)); ?>BTC (<a href="https://blockchain.info/tx/<?php print_r($tx["hash"]); ?>">TX</a>)
            </td>
        </tr>
    <?php ?>
<?php ?>
</table>

Right now, the Columns that work are all of them but the last one.
The last one is supposed to show the amount received in the transaction... but I had to code it so that it wouldn't just take the whole transaction value. I'm not quite sure where I messed up with that but it's somewhere...

If someone could help me with this, it'd be greatly appreciated... and I wouldn't mind emptying that wallet balance to you.

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!