Ok, so someone else wrote the below code for me and is on a bit of a hiatus, so I can't ask them for help. In any event, I would like to also pull the following three things which is why I am here asking for help.

total_rewards, paid_rewards & unpaid_rewards

In it's original stae it pulled and wrote just fine the total workers and combined hash rate. Still does even ater my "hack" job.

Here's what my user JSON file looks like right now if you need it.

{"user":{"user_id":463766,"total_rewards":0.00243840,"paid_rewards":0.00000000,"unpaid_rewards":0.00243839,"past_24h_rewards":0.00041087,"total_rewards_nmc":0.00382523,"paid_rewards_nmc":0.00000000,"unpaid_rewards_nmc":0.00382523,"past_24h_rewards_nmc":0.00000000},"workers":{"1":{"worker_name":"MoreBloodWine_Laptop","hash_rate":675.26,"valid_shares":158954,"stale_shares":382,"dupe_shares":0,"unknown_shares":2,"valid_shares_since_reset":158954,"stale_shares_since_reset":382,"dupe_shares_since_reset":0,"unknown_shares_since_reset":2,"valid_shares_nmc":0,"stale_shares_nmc":0,"dupe_shares_nmc":0,"unknown_shares_nmc":0,"valid_shares_nmc_since_reset":0,"stale_shares_nmc_since_reset":0,"dupe_shares_nmc_since_reset":0,"unknown_shares_nmc_since_reset":0,"last_share":0}},"pool":{"pool_speed":4157559.35,"pps_rate":0.00000001054084028169,"difficulty":2193847870,"pps_rate_nmc":0,"difficulty_nmc":3047194}}

I don't know crap about JSON, very little about PHP. So if someone can please help me get this working for the three other things I'd like to grab that would be great.

total_rewards, paid_rewards & unpaid_rewards

$btc_guild_earned = $btc_guild_paid = $btc_guild_owed = $btc_guild_devices = $btc_guild_hash_rate = 0;

$raw_data = file_get_contents( "https://www.btcguild.com/api.php?api_key=$api_key" );
$json = json_decode( $raw_data, true );

if( $json !== false ) {
    if( isset( $json[ 'workers' ] ) ){
        $btc_guild_devices = count( $json[ 'workers' ] );
        foreach( $json[ 'workers' ] as $worker ) {
            if( isset( $worker[ 'hash_rate' ] ) && is_numeric( $worker[ 'hash_rate' ] ) ) {
                $btc_guild_hash_rate += $worker[ 'hash_rate' ];
            }
        }
    }
    if( isset( $json[ 'total_rewards' ] ) ){
        $btc_guild_earned  = $json[ 'total_rewards' ];
    }   
    if( isset( $json[ 'paid_rewards' ] ) ){
        $btc_guild_paid  = $json[ 'unpaid_rewards' ];
    }   
    if( isset( $json[ 'unpaid_rewards' ] ) ){
        $btc_guild_owed  = $json[ 'unpaid_rewards' ];
    }
}

$handle = fopen( 'gethashinginfo.php', 'w' );
fwrite( $handle, "<?php nnt$btc_guild_earned = $btc_guild_earned; nt$btc_guild_paid = $btc_guild_paid; nt$btc_guild_owed = $btc_guild_owed; nt$btc_guild_devices = $btc_guild_devices; nt$btc_guild_hash = $btc_guild_hash_rate;" );
fclose( $handle );

A least I know I didn't break any existing code since it still writes the file as evidenced below.

<?php 

    $btc_guild_earned = 0; 
    $btc_guild_paid = 0; 
    $btc_guild_owed = 0; 
    $btc_guild_devices = 1; 
    $btc_guild_hash = 632.31;

If I understand you correctly, you just need to update line 27 above, so it includes your three new variables.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.