Okay i have 2 variable named bid price and offer price . I need to fill in the values into the variables through cases.

For each row of data ,i want to retrieve the rates for the currency pairs (eg. eur/usd,audusd) . I have 2 values for each currency for bid and offer price which are already defined( eg $bid ,$bid1,$bid2,$bid3,$bid4,$bid5,$bid6.) For clarification , one pair has 2 variables which i want to put the variables in. So EG. if the row's currency pair is eur/usd , i want to take $bid and $bid1 or if its usd/jpy, i want to take $bid2 and $bid3. so these go by a case basis which does it in a for-each/while loop ( row). So now i want to echo the bidpricepl and offerpricepl out for each row beside the table depending on what the selection, how do i do that?

For the displaying of the table rows

  while($row = mysql_fetch_array($result)){   //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>" . $row['profitandloss'] . "</td><td><a href ='delete.php?id=".$row['trade_id']."'>X</a></td></tr>";  //$row['index'] the index here is a field name
    }
    echo "</table>";
 ** include 'functions.php';
echo "<table border = '1px'>"; // start a table tag in the HTML
while($row = mysql_fetch_array($result)){  
echo assignment();// im sure this part is the error. but i dont know how to. i want to echo the bid and offer pl beside each row
}
echo "</table>";
    **

Condition Function
Function to assign the values to the 2 variable based on a if else statement

function assignment(){
    if (($row['selection'])=='eur/usd')
            {
            $bid==$bidpricepl;
            echo $bidpricepl;
            $bid1==$offerpricepl;
            echo $offerpricepl;
            }
    elseif (($row['selection'])=='usd/jpy')
            {
            $bid2==$bidpricepl;
            echo $bidpricepl;
            $bid3==$offerpricepl;
            echo $offerpricepl;
            }
    elseif (($row['selection'])=='usd/cad')
            {
            $bid4==$bidpricepl;
            echo $bidpricepl;
            $bid5==$offerpricepl;
            echo $offerpricepl;
            }
    elseif (($row['selection'])=='eur/jpy')
            {
            $bid6==$bidpricepl;
            echo $bidpricepl;
            $bid7==$offerpricepl;
            echo $offerpricepl;
            }
    elseif (($row['selection'])=='eur/chf')
            {
            $bid8==$bidpricepl;
            echo $bidpricepl;
            $bid9==$offerpricepl;
            echo $offerpricepl;
            }
    elseif (($row['selection'])=='gbp/usd')
            {
            $bid10==$bidpricepl;
            echo $bidpricepl;
            $bid11==$offerpricepl;
            echo $offerpricepl;
            }
    elseif (($row['selection'])=='aud/usd')
            {
            $bid12==$bidpricepl;
            echo $bidpricepl;
            $bid13==$offerpricepl;
            echo $offerpricepl;
            }
    elseif (($row['selection'])=='usd/chf')
            {
            $bid14==$bidpricepl;
            echo $bidpricepl;
            $bid15==$offerpricepl;
            echo $offerpricepl;
            }
        }

The issues with your function are:

  • The function has it own scope so $row array is unknown to it. Pass the $row array as a parameter.
  • the code $bid==$bidpricepl; and other similar do nothing (== is a comparison operator)
  • if the function echoes something you do not use it the way you did echo assignment(); but just call it assignment();
  • there are unknown variables in the function such as $bidpricepl and $offerpricepl, which have not been declared within the function scope
  • the logic of the function is unclear; I am not sure if I understood the requrement for it from your post either.
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.