php - How to add formula which is sum of $Quantity and display at the bottom? How to auto numbered list when data is fetched? -
mysql_select_db("fyp",$connect); $sql="select * `table 1` year='$year'"; //query database $query=mysql_query($sql,$connect); while($hdata=mysql_fetch_array($query)) { $country=$hdata['country']; $method=$hdata['method']; $type=$hdata['type']; $pline=$hdata['pline']; $ptype=$hdata['ptype']; $year=$hdata['year']; $quarter=$hdata['quarter']; $revenue=$hdata['revenue']; $quantity=$hdata['quantity']; echo "<tr>"; echo "<td align='middle'>$country</td>"; echo "<td align='middle'>$method</td>"; echo "<td align='middle'>$type</td>"; echo "<td align='middle'>$pline</td>"; echo "<td align='middle'>$ptype</td>"; echo "<td align='middle'>$year</td>"; echo "<td align='middle'>$quarter</td>"; echo "<td align='middle'>$revenue</td>"; echo "<td align='middle'>$quantity</td>"; echo "</tr>"; } ?>
$query=mysql_query($sql,$connect); $sum_quantity = 0; $i = 1; while($hdata=mysql_fetch_array($query)) { $country=$hdata['country']; $method=$hdata['method']; $type=$hdata['type']; $pline=$hdata['pline']; $ptype=$hdata['ptype']; $year=$hdata['year']; $quarter=$hdata['quarter']; $revenue=$hdata['revenue']; $quantity=$hdata['quantity']; $sum_quantity += $quantity; echo "<tr>"; echo "<td align='middle'>$i</td>"; echo "<td align='middle'>$country</td>"; echo "<td align='middle'>$method</td>"; echo "<td align='middle'>$type</td>"; echo "<td align='middle'>$pline</td>"; echo "<td align='middle'>$ptype</td>"; echo "<td align='middle'>$year</td>"; echo "<td align='middle'>$quarter</td>"; echo "<td align='middle'>$revenue</td>"; echo "<td align='middle'>$quantity</td>"; echo "</tr>"; $i++; }
Comments
Post a Comment