0

我正在尝试检索数据并将其放入我的数据库中。$bid 、 $bid1 、 $bid2 、 bidpricepl 、 offerpricepl 已经定义。除了从 db 中检索到的所有行描述之外,还有一行,损益是一个变量。Foreach row ,这个变量的值被推低一个档次,意味着在placement 2中,值是placement 1。我附上了一张图片,以便你们理解。我的查询有什么问题?EG表

OrderNumber: 利润损失:
sadasdasd BLANK
sadasdasd 1
sadasdasd 2
sadasdasd 3

调用和显示查询

$query = "SELECT * FROM opentrades"; //You don't need a ; like you do in SQL
$result = mysql_query($query);
echo "<table border = '1px'>"; // start a table tag in the HTML
echo "<tr><td>" . "Order Number" . "</td><td>" . "Selection" . "</td><td>" . "Date" . "</td><td>" . "Type" . "</td><td>" . "Size" . "</td><td>" . "Bid Price" . "</td><td>" . "Offer Price" . "</td><td>" ."Stop Loss" . "</td><td>" . "Take Profit" . "</td><td>" ."Profit/Loss"."</td><td>" ."Close"."</td></tr>" ;  //$row['index'] the index here is a field name

while($row = mysql_fetch_array($result,MYSQLI_BOTH)){   //Creates a loop to loop through results
echo "<tr><td>" . $row['trade_id'] . "</td><td>" . $row['selection'] . "</td><td>" . $row['date'] ."</td><td>" . $row['type'] ."</td><td>" . $row['size'] ."</td><td>" . $row['bidprice'] ."</td><td>" . $row['offerprice'] ."</td><td>" . $row['stoploss'] ."</td><td>" . $row['takeprofit'] ."</td><td>" . $bidpricepl  . "</td><td><a href ='delete.php?id=".$row['trade_id']."'>X</a></td></tr>";  
if ($row['selection']=='eur/usd')
            {
            $bidpricepl=$bid;

            $offerpricepl=$bid1;

            }
    elseif ($row['selection']=='usd/jpy')
            {
            $bidpricepl=$bid2;

            $offerpricepl=$bid3;

            }
    elseif ($row['selection']=='usd/cad')
            {
            $bidpricepl=$bid4;

            $offerpricepl=$bid5;

            }
    elseif ($row['selection']=='eur/jpy')
            {
            $bidpricepl=$bid6;

            $offerpricepl=$bid7;

            }
    elseif ($row['selection']=='eur/chf')
            {
            $bidpricepl=$bid8;

            $offerpricepl=$bid9;

            }
    elseif ($row['selection']=='gbp/usd')
            {
            $bidpricepl=$bid10;

            $offerpricepl=$bid11;

            }
    elseif ($row['selection']=='aud/usd')
            {
            $bidpricepl=$bid12;

            $offerpricepl=$bid13;

            }
    elseif ($row['selection']=='usd/chf')
            {
            $bidpricepl=$bid14;

            $offerpricepl=$bid15;

            }



}
echo "</table><br>";
4

1 回答 1

0

尝试将if代码移动到echo语句之前。

目前,您正在计算表中的行输出后的值。

例如

if ($row['selection']=='eur/usd')
..
elseif ($row['selection']=='usd/jpy')
elseif ($row['selection']=='usd/cad')
elseif ($row['selection']=='eur/jpy')
elseif ($row['selection']=='eur/chf')
elseif ($row['selection']=='gbp/usd')
elseif ($row['selection']=='aud/usd')
elseif ($row['selection']=='usd/chf')

echo "<tr><td>" . $row['trade_id'] . "</td><td>" . $row['selection'] . "</td><td>" . $row['date'] ."</td><td>" . $row['type'] ."</td><td>" . $row['size'] ."</td><td>" . $row['bidprice'] ."</td><td>" . $row['offerprice'] ."</td><td>" . $row['stoploss'] ."</td><td>" . $row['takeprofit'] ."</td><td>" . $bidpricepl  . "</td><td><a href ='delete.php?id=".$row['trade_id']."'>X</a></td></tr>"; 
于 2013-08-16T08:12:09.887 回答