Couldn't find a specific answer to this so thought I'd ask. In short, I have a table that retrieves information from an API, based on data stored in my database and all I want to do is to get a total of certain, not all, columns from that table so that I can use them elsewhere on the site. As an example, let's use the Profit/Loss column and Total Divi. Do I have to store the results as an array so that I can retrieve it elsewhere or is it something different?
PHP Code:
<?php
$arr = array();
for($x=0;$x<$y;$x++)
{?>
<tr>
<td class="input"><?php
if($pri[$x] > $lastprice[$x])
{
$pnl= ($lastprice[$x]-$pri[$x]) * $vol[$x];
echo $pnl;
}
else if($pri[$x] < $lastprice[$x])
{
$pnl= ($lastprice[$x]-$pri[$x]) * $vol[$x];
echo $pnl;
}
else
echo '0';
?></td>
<td><?php
$div = file_get_contents("https://api.iextrading.com/1.0/stock/market/batch?symbols=$symbol[$x]&types=stats&filter=dividendRate");
$div = json_decode($div,TRUE);
foreach($div as $divi => $value) {
echo $value['stats']['dividendRate'];
}
?></td>
<td><?php
$firstno = floatval($vol[$x]);
$secondno = floatval($value['stats']['dividendRate']);
$sum = $firstno * $secondno;
print ($sum);
?></td>
</tr>
<?php }
$arr[$x] = array('pnl' => $pnl, 'sum' => $sum);
var_dump($arr);
?>
</table>
So I only left the profit/loss row/column as well as dividend amount (2nd column) and dividend total, just so you can see how I get these numbers in the first place.
Here's a screenshot of what data I want to add up, just to clarify:
https://imgur.com/a/HVZ0K For example, last row, I want to add 0, 0, 25.2 & 73 together to be able to display it somewhere else.
Thanks in advance!
CodingForums...
ما را در سایت CodingForums دنبال می کنید
برچسب : نویسنده : codingforums بازدید : 207 تاريخ : سه شنبه 10 بهمن 1396 ساعت: 16:45