How to multiply two values in a PHP table to get total?

Veritas

New Member
So i have a table that displays data from my database and i want to add in a total field, anyway how would i get the amount and the price to multiply and then display into the new total field?here is my code so far \[code\]<?php// Connection data (server_address, database, name, poassword)$hostdb = 'localhost';$namedb = 'xxxx';$userdb = 'xxxx';$passdb = '';try {// Connect and create the PDO object$conn = new PDO("mysql:host=$hostdb; dbname=$namedb", $userdb, $passdb);$conn->exec("SET CHARACTER SET utf8"); // Sets encoding UTF-8// Define and perform the SQL query$sql = "SELECT `id`, `wine`, `amount`, `price`, `upc` FROM `wine`";$result = $conn->query($sql);// If the SQL query is succesfully performed ($result not false)if($result !== false) {// Create the beginning of HTML table, and the first row with colums title$html_table = '<table border="1" cellspacing="0" cellpadding="2"><tr><th>ID</th> <th>Wine</th><th>Amount</th><th>Price</th><th>upc</th></tr>';// Parse the result set, and adds each row and colums in HTML tableforeach($result as $row) { $html_table .= '<tr><td align="center">' .$row['id']. '</td><td align="center">' .$row['wine']. '</td><td align="center">' .$row['amount']. '</td><td align="center">' .$row['price']. '</td><td align="center">' .$row['upc']. '</td></tr>'; }} $conn = null; // Disconnect $html_table .= '</table>'; // ends the HTML table echo $html_table; // display the HTML table}catch(PDOException $e) {echo $e->getMessage();}?><a href="http://stackoverflow.com/admin/">Admin</a> \[/code\]
 
Back
Top