缺少检索数据库的第一行

时间:2013-08-16 07:57:42

标签: php sql

我正在尝试检索数据并将其简单地放入我的数据库中。 $ bid,$ bid1,$ bid2,bidpricepl,offerpricepl已经定义。除了从db中检索的所有行描述之外,还有一行,损益是一个变量。 Foreach行,这个变量的值被推下一个档位,意思是位置2,值是地点1.我附上了一个图像,以便你们理解。我的查询是什么问题? EG TABLE

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>";

1 个答案:

答案 0 :(得分:0)

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

在输出表格中的行后,您正在计算该值。

E.g。

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>";