PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
JimiH
Forum Commoner
Posts: 92 Joined: Thu Jun 15, 2006 6:10 am
Post
by JimiH » Fri Oct 27, 2006 7:21 am
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
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Fri Oct 27, 2006 10:40 am
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.
JimiH
Forum Commoner
Posts: 92 Joined: Thu Jun 15, 2006 6:10 am
Post
by JimiH » Sun Oct 29, 2006 6:13 am
Thanks I'll have a go.
Geoff
JimiH
Forum Commoner
Posts: 92 Joined: Thu Jun 15, 2006 6:10 am
Post
by JimiH » Sun Oct 29, 2006 6:40 am
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