خرید بک لینک
Not sure how to exactly ask this question so let me try to explain. I'm trying to display dividend amount data for each stock (stock symbol stored in db) inside of a table. This dividend data is coming from the IEX API and while I can echo out the results normally and just get them in a list, like this: FB : 0 GOOGL : 0 AAPL : 2.52 I don't know how to display them inside of a table row, for each of those stocks. I just get AAPL : 2.52 for all rows. So it essentially seems like at some point it doesn't know what data to get for what stock and just prints AAPL for all three. This is the code (some unrelated hidden to make it shorter):

PHP Code:

<?php
    
// Initialising variables to store extracted information
    
$name = [];
    
$symbol = [];
    
$open = [];
    
$close = [];
    
$high = [];
    
$low = [];
    
$lastprice = [];
    
$y 0;
    
$z '';
    
$key "93dcc722279c3a7577f248b09ef6167f";

$memberid $_SESSION['memberID'];
$sql "SELECT * FROM portfolio WHERE memberID = $memberid";
$result mysqli_query($co$sql);

// Check if databse is empty
if (mysqli_num_rows($result) > 0
{
    while(
$row mysqli_fetch_assoc($result)) 
    {
        
$sym[$y] = $row["stocks_symbol"];
        
$pri[$y] = $row["price"];
        
$vol[$y] = $row["quantity"];
        
$id[$y] = $row["memberid"];
        
$y += 1;
    }
}
// If database empty
else 
{
    
?><h1><center><?php
    
echo "Portfolio Empty";
    
?></h1></center><?php
    
die();
}
mysqli_close($co);

// Adding all stock names in one variable to enable API call
for($a=0;$a<$y;$a++)
{
    
$z $z.$sym[$a].',';
}

$z rtrim($z,",");


// API call
$contents file_get_contents("http://marketdata.websol.barchart.com/getQuote.json?key=$key&symbols=$z&mode=R");
$contents json_decode($contentstrue);

$div file_get_contents("https://api.iextrading.com/1.0/stock/market/batch?symbols=$z&types=stats&filter=dividendRate");  
$div json_decode($div,TRUE);  
foreach(
$div as $divi => $value) {
echo 
'<br/>'$divi.' : '$value['stats']['dividendRate'];
}

// Check successfull API call
if($contents["status"]["code"] == 200
{
    foreach(
$contents['results'] as $result
    {
        
array_push($name,$result['name']);
        
array_push($symbol,$result['symbol']);
        
array_push($open,$result['open']);
        
array_push($close,$result['close']);
        
array_push($high,$result['high']);
        
array_push($low,$result['low']);
        
array_push($lastprice,$result['lastPrice']);
    }

}        
// If API call unsuccessful
else 
{
    
?>
    <h1><center>"Error retreiving data. Please try again later."</center></h1>
    <?php
    
die();
}
?>
<!-- Generating Output in tabular format -->
<table class='table table-responsive'>
    <tr class='head warning'>
        <td>Name</td>
        <td>Symbol</td>
        <td>Open</td>
        <td>Close</td>
        <td>High</td>
        <td>Low</td>
        <td>Last Price</td>
        <td>Price Bought</td>
        <td>Quantity</td>
        <td>Change Per Stock</td>
        <td>Profit/Loss</td>
        <td>Advanced Data</td>
        <td>Dividend</td>
    </tr>
    <?php
        
for($x=0;$x<$y;$x++) 
        {
?>
            <tr>
                <td><?php echo $name[$x]; ?></td>
                <td><?php echo $symbol[$x]; ?></td>
                <td><?php echo $open[$x]; ?></td>
                <td><?php echo $close[$x]; ?></td>
                <td><?php echo $high[$x]; ?></td>
                <td><?php echo $low[$x]; ?></td>
                <td><?php echo $lastprice[$x]; ?></td>
                <td><?php echo $pri[$x]; ?></td>
                <td><?php echo $vol[$x]; ?></td>
                <td><?php 
                    
if($pri[$x] > $lastprice[$x]) 
                    {
?>
                        <i class="fa fa-arrow-down">
                        <?php echo $lastprice[$x]-$pri[$x];
                    }
                    else if(
$pri[$x] < $lastprice[$x]) 
                    {
?>
                        </i>
                        <i class="fa fa-arrow-up">
                        <?php echo $lastprice[$x]-$pri[$x];
                        
?></i><?php
                    
}
                    else
                        echo 
'0';
                    
?></td>

                <td><?php 
                    
if($pri[$x] > $lastprice[$x])
                    {
?>
                        <i class="fa fa-arrow-down">
                        <?php echo ($lastprice[$x]-$pri[$x]) * $vol[$x];
                    }
                    else if(
$pri[$x] < $lastprice[$x]) 
                    {
?>
                        </i>
                        <i class="fa fa-arrow-up">
                        <?php echo ($lastprice[$x]-$pri[$x]) * $vol[$x];
                        
?></i><?php
                    
}
                    else
                        echo 
'0'?>
                </td>
                <td><center><button id="opener1" class='btn btn-success' >Click to view advanced data</button></center>
                    <div id="dialog1" title="Advanced Company Data">Company Description:<br></div>
                    <script>
                    $("#dialog1").dialog({
                        autoOpen: false
                             });
                        $("#opener1").click(function() {
                        $("#dialog1").dialog("open", "modal", true );
                             });
                    </script>
                </td>

                <td>
                     <?php echo '<br/>'$divi.' : '$value['stats']['dividendRate']; ?>
                </td>

            </tr>
        <?php ?>
</table>

In short, I'm asking about the last 'td' in the table and how to change it so that it displays the dividend amount for the correct symbol in the row, not AAPL for all.

برچسب: نویسنده: آیلین رضوانی تاريخ: دوشنبه 2 بهمن 1396 ساعت: 18:47

صفحه بندی