The query is return an empty value on the frist row which means that the supposed value in the first row is in the second row , etc etc . How do i correct this?

    $query1 = "SELECT * FROM opentrades"; //You don't need a ; like you do in SQL
    $result1 = mysql_query($query1);
    echo "<table border = '1px'>"; // start a table tag in the HTML
    while($row1 = mysql_fetch_array($result1)){  
    echo "<tr><td>" . "Selection" . "</td><td>" . "Profit/Loss" . "</td></tr>";
    echo "<tr><td>" . $row1['selection']."<td>".$offerpricepl. "</tr>";
    if ($row1['selection']=='eur/usd')
                {
                $bidpricepl=$bid;


            $offerpricepl=$bid1;

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

            $offerpricepl=$bid3;

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

            $offerpricepl=$bid5;

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

            $offerpricepl=$bid7;

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

            $offerpricepl=$bid9;

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

            $offerpricepl=$bid11;

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

            $offerpricepl=$bid13;

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

            $offerpricepl=$bid15;

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

I don't know what happens, maybe you have an empty row in your database. Your code seem equal to Click Here
On option in your code that you lack an else-clause so if the row does not fit in the else-ifs, no value will be put in the cell.
In this link you can also read that fetch_array is depreciated from php 5.5.0. May you can solve it by using the MySQLi variant, see Click Here.

But where is the problem???

The problem is that $offerpricepl is not defined yet in the first iteration of the while loop. Put the test first and then echo the row:

...
while($row1 = mysql_fetch_array($result1)){  

    // this is the heading row
    echo "<tr><td>" . "Selection" . "</td><td>" . "Profit/Loss" . "</td></tr>";

    // now define the value of the $offerpricepl variable
    if ($row1['selection']=='eur/usd')
                {
                $bidpricepl=$bid;


            $offerpricepl=$bid1;

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

            $offerpricepl=$bid3;

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

            $offerpricepl=$bid5;

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

            $offerpricepl=$bid7;

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

            $offerpricepl=$bid9;

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

            $offerpricepl=$bid11;

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

            $offerpricepl=$bid13;

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

            $offerpricepl=$bid15;

            }

    // now you can use the $offerpricepl variable
    echo "<tr><td>" . $row1['selection']."<td>".$offerpricepl. "</tr>";
}
echo "</table><br>";

The code would be also cleaner if you used switch instead of if / elseif.

Also I do not know why heading row must be repeated each iteration.

commented: this solves the question I think +3

I couldn't get the value of $offerpricepl

echo "<tr><td>" . $row1['selection']."<td>".$offerpricepl. "</tr>"; // There is missing the value of $offerpricepl variable and it will not define anywhere..

I think It should be $offerprice1=$row1['fsomefieldname']; then we can get the iterate value.

One more suggestion I would like to add here:

echo "<tr><td>" . "Selection" . "</td><td>" . "Profit/Loss" . "</td></tr>";  //That should be out of while loop so that heading will not repeat and for structured output.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.