0

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>";
Attachments z.JPG 36.16 KB
4
Contributors
4
Replies
38
Views
4 Years
Discussion Span
Last Post by stevie.whalen
1

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.

Edited by C#Jaap: I saw after all a flaw in the code

1

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.

Edited by broj1

Votes + Comments
this solves the question I think
0

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.

Edited by pritaeas: Added markdown for code.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.