使用数据库中的 while 循环填充数组
populate array with while loop from database
我想用硬币支付创建大规模提款api。
它应该看起来像这样
$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
);
所以我想用 while 循环将所有提款填充到一个数组中
提前致谢
我就是这样做的
$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);
更新
我已经能够得到这个数组
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
)
)
堆叠实现'wd[wd1][amount]'
为了实现所需的数组,替换这部分:
$y['wd'.$i]['amount']=$f['amount'];
$y['wd'.$i]['ecurrency_address']=$f['ecurrency_address'];
$y['wd'.$i]['currency']='BTC';
有了这个:
$y['wd[wd'.$i.'][amount]'] = $f['amount'];
$y['wd[wd'.$i.'][ecurrency_address]'] = $f['ecurrency_address'];
$y['wd[wd'.$i.'][currency]'] = $f['BTC'];
我想用硬币支付创建大规模提款api。 它应该看起来像这样
$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
);
所以我想用 while 循环将所有提款填充到一个数组中 提前致谢 我就是这样做的
$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);
更新
我已经能够得到这个数组
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
)
)
堆叠实现'wd[wd1][amount]'
为了实现所需的数组,替换这部分:
$y['wd'.$i]['amount']=$f['amount'];
$y['wd'.$i]['ecurrency_address']=$f['ecurrency_address'];
$y['wd'.$i]['currency']='BTC';
有了这个:
$y['wd[wd'.$i.'][amount]'] = $f['amount'];
$y['wd[wd'.$i.'][ecurrency_address]'] = $f['ecurrency_address'];
$y['wd[wd'.$i.'][currency]'] = $f['BTC'];