Jump to content

Help with PHP code


suprsnipes

Recommended Posts

I'm really struggling and need some help with PHP code.

 

I have created a connection to the database and can run various queries. As you can see from the basic code below I can connect and display the result of a query but I would like to run an if/else statement on the data prior to echoing (the layout would be the same) and would like to know how to go about this, perhaps an example of some kind would help.

 

<?php
$con = mysql_connect("","","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("day", $con);

$result = mysql_query("SELECT * FROM test INNER JOIN trades ON test.id1=trades.id-1");

echo "<table border='1'>
<tr>
<th>ID1</th>
<th>SYMBOL1</th>
<th>DATE1</th>
<th>TIME1</th>
<th>TYPE1</th>
<th>PRICE1</th>
<th>SIZE1</th>
<th>ID</th>
<th>SYMBOL</th>
<th>DATE</th>
<th>TIME</th>
<th>TYPE</th>
<th>PRICE</th>
<th>SIZE</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['ID1'] . "</td>";
  echo "<td>" . $row['SYMBOL1'] . "</td>";
  echo "<td>" . $row['DATE1'] . "</td>";
  echo "<td>" . $row['TIME1'] . "</td>";
  echo "<td>" . $row['TYPE1'] . "</td>";
  echo "<td>" . $row['PRICE1'] . "</td>";
  echo "<td>" . $row['SIZE1'] . "</td>";
  echo "<td>" . $row['ID'] . "</td>";
  echo "<td>" . $row['SYMBOL'] . "</td>";
  echo "<td>" . $row['DATE'] . "</td>";
  echo "<td>" . $row['TIME'] . "</td>";
  echo "<td>" . $row['TYPE'] . "</td>";
  echo "<td>" . $row['PRICE'] . "</td>";
  echo "<td>" . $row['SIZE'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?> 

 

Regards,

suprsnipes

Link to comment
https://forums.phpfreaks.com/topic/161355-help-with-php-code/
Share on other sites

This is what I want to do.

 

This code should be ok, a friend has helped me with it, I've just updated it now best I could for the moment. Should make things a little clearer.

 

action == "buy" or "sell", not sure what to do with this.

 

At this stage I don't know if I should use the below if/else statement to UPDATE the type1 column in the database or if there is another option as I have read that it's not ideal to put calculated values into a database...

 

<?php
// Classification of trades
if (type == "N") {

   if (type1 != null) {

     if (type1 == "buy") {
   
       if (price >= price1) {
         action == "buy";
       }
       else {
         action == "sell";
       }
     }
     else if (type1 == "sell") {
   
       if (price <= price1) {
         action == "sell";
       }
       else {
         action == "buy";
       }
     }
   }
   else {

     if (type1 == "a") {

       if (price >= price1) {
         action == "buy";
       }
       else {
         action == "sell";
       }
     }
     if (type1 == "b") {

       if (price > price1) {
         action == "buy";
       }
       else {
         action == "sell";
       }
     }
   }
}
?>

Link to comment
https://forums.phpfreaks.com/topic/161355-help-with-php-code/#findComment-851480
Share on other sites

The query joins the tables with the intention of referring to the previous ID's data using an IF statement.

 

Using the IF statement I want to classify the trades (N) as a buy or a sell, but I'm not sure where I place this in my PHP code...I'm also uncertain as to whether or not I update the data in the database or I do this in some other manner as I have read that you should not put calculated values into a database...

Link to comment
https://forums.phpfreaks.com/topic/161355-help-with-php-code/#findComment-851920
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.