Page 1 of 1

Add field values from MySQL

Posted: Fri Oct 27, 2006 7:21 am
by JimiH
Hello

I have the code below

Code: Select all

include("conn.php");


$result = mysql_query("SELECT * FROM projects where status = 'O'") or die(mysql_error());


echo "<table Align ='center' border='1'>"; 
echo "<tr> <th>VSI Number</th> <th>Customer</th> <th>Engineer</th> <th>Value (£)</th> <th>Year Qty</th><th>Total (£)</th>  <th>Comments</th> <th>Last update</th> </tr>";
 
// keeps getting the next row until there are no more to get 

while($row = mysql_fetch_array( $result )) { 

// Print out the contents of each row into a table 

echo "<tr><td>"; 
echo $row['VSI_NUMBER']; 
echo "</td><td>"; 
echo $row['CUSTOMER']; 
echo "</td><td>"; 
echo $row['ENGINEER']; 
echo "</td><td>"; 
echo $row['VALUEExworks']; 
echo "</td><td>"; 
echo $row['YEARQTY'];
echo "</td><td>"; 
echo $row['COMMENTS']; 
echo "</td><td>"; 
echo $row['ACTIONDATE']; 
echo "</td></tr>";
 } 
echo "</table>"; 

?> 


</body>

</html>
I have added a columb "Total (£)" and would like to include the result of "VALUEExworks" multiplied by "YEAR QTY" into this row.

How would I achieve this?

Thanks

Geoff

Posted: Fri Oct 27, 2006 10:40 am
by RobertGonzalez

Code: Select all

<?php
while($row = mysql_fetch_array( $result )) {
  // Print out the contents of each row into a table

  $total = $row['VALUEExworks'] * $row['YEARQTY'];

  echo "<tr><td>";
  echo $row['VSI_NUMBER'];
  echo "</td><td>";
  echo $row['CUSTOMER'];
  echo "</td><td>";
  echo $row['ENGINEER'];
  echo "</td><td>";
  echo $row['VALUEExworks'];
  echo "</td><td>";
  echo $row['YEARQTY'];
  echo "</td><td>";
  echo $row['COMMENTS'];
  echo "</td><td>";
  echo $row['ACTIONDATE'];
  echo "</td></tr>";
}
echo "</table>";

?>
Then echo $total out where you want it to go in the output.

Posted: Sun Oct 29, 2006 6:13 am
by JimiH
Thanks I'll have a go.

Geoff

Posted: Sun Oct 29, 2006 6:40 am
by JimiH
Thanks worked a treat!!

Code: Select all

$total = $row['VALUEExworks'] * $row['YEARQTY']; 

echo "<tr><td>"; 
echo $row['VSI_NUMBER']; 
echo "</td><td>"; 
echo $row['CUSTOMER']; 
echo "</td><td>"; 
echo $row['ENGINEER']; 
echo "</td><td>"; 
echo $row['VALUEExworks']; 
echo "</td><td>"; 
echo $row['YEARQTY'];
echo "</td><td>"; 
echo $total;
echo "</td><td>"; 
echo $row['COMMENTS']; 
echo "</td><td>"; 
echo $row['ACTIONDATE']; 
echo "</td></tr>";
 } 
echo "</table>";
Geoff