0

i want to create a mass withdrawal with coinpayments api. and it should look like this

$req = array(
    'wd[wd1][amount]' => 1.00, //amount will be fetched from database
    'wd[wd1][address]' => '1BitcoinAddress', //btc address from database
    'wd[wd1][currency]' => 'BTC',
    'wd[wd2][amount]' => 0.0001,
    'wd[wd2][address]' => '1BitcoinAddress',
    'wd[wd2][currency]' => 'BTC',
    'wd[wd3][amount]' => 0.0001,
    'wd[wd3][address]' => '1BitcoinAddress',
    'wd[wd3][currency]' => 'BTC',
//[wd4] for the fifth withdrawal and so on
    );

So i want to populate all withdrawals into one array with while loop thanks in advance this is how i did it

    $q = "SELECT amount, ecurrency_address, 1week FROM Tablename WHERE status = 'Processed'";
    $r = mysqli_query($mysqli, $q) or die ("Error");

        $i = 0;
        $j = 0;
    while($f = mysqli_fetch_assoc($r)){
       ++$j;

        if($j === 2){
            $j = 1;
            $i = ++$i;
        }

        $y['wd'.$i]['amount']=$f['amount'];
        $y['wd'.$i]['ecurrency_address']=$f['ecurrency_address'];
        $y['wd'.$i]['currency']='BTC';
}

echo '<pre>';
print_r($y);

UPDATE

I have been able to get this array

Array
(
    [wd1] => Array
        (
        [amount] => 0.05
        [ecurrency_address] => 1BitcoinAddress
        [currency] => BTC
    )

[wd2] => Array
    (
        [amount] => 10
        [ecurrency_address] => 1BitcoinAddress
        [currency] => BTC
    )

[wd3] => Array
    (
        [amount] => 96
        [ecurrency_address] => 1BitcoinAddress
        [currency] => BTC
    )

)

stacked at achieving 'wd[wd1][amount]'

wowkin2
  • 5,895
  • 5
  • 23
  • 66
justice
  • 75
  • 1
  • 2
  • 11
  • 2
    so where's the problem apart from your spare time to code that? – Jeff Aug 19 '17 at 01:11
  • my problem is to how to put them in the array like that. please help – justice Aug 19 '17 at 01:18
  • 4
    [read about arrays](http://php.net/manual/en/language.types.array.php), give it try and you are welcome to come back if you have problems. This is not a coding service. – Jeff Aug 19 '17 at 01:19
  • ok thanks. but any clue on what i should use? using the while loop – justice Aug 19 '17 at 01:21
  • before loop: `$i=0;` inside loop: `$y['wd'.$i]=$f; $i++;` after loop: `var_dump($y);` – Jeff Aug 19 '17 at 01:25
  • Please help. i have manage to get this `$y[wd1] [amount]= $f $y[wd2] [amount]= $f` but how to get this is the problem. adding the wd 'wd[wd1][amount]' = $f 'wd[wd2][amount]' = $f – justice Aug 19 '17 at 11:43
  • change `$y['wd1']['amount'] = $f;` for `$y['wd'.$i]['amount] = $f;` where `$i` is your loop counter. Otherwise you'll be overwriting the same element on each iteration of the loop – William Perron Aug 19 '17 at 20:34
  • yh thats how i did it. updating it above – justice Aug 19 '17 at 21:21
  • but how to add the 'wd' to each of the key is what im looking at. thanks because documentation says it is required – justice Aug 19 '17 at 21:33

1 Answers1

1

To achieve the array required, replace this part:

$y['wd'.$i]['amount']=$f['amount'];
$y['wd'.$i]['ecurrency_address']=$f['ecurrency_address'];
$y['wd'.$i]['currency']='BTC';

With this:

$y['wd[wd'.$i.'][amount]'] = $f['amount'];
$y['wd[wd'.$i.'][ecurrency_address]'] = $f['ecurrency_address'];
$y['wd[wd'.$i.'][currency]'] = $f['BTC'];
Dmitriy Kravchuk
  • 476
  • 4
  • 16