echoing an AVG value from a virtual value with mysql and php -
i have following query , gives me percentage. works great , echo in table. in table want echo avg % total.i.e have 12 months of year , want avg. % year @ bottom of table. have worked out how valuations , instructions stored in database. but.. how do 'virtual' column %..as has been created query , not physical column in database.
iam starting think need combine total valuations total instructions %. ideas how can this?
$query= "select *, concat(round(( instructions/valuations * 100 ),0),'%') percentage office_figures2016"; $result = mysqli_query($conn, $query); while($office_figures2016=mysqli_fetch_assoc($result)){
it echos :
echo"".$office_figures2016['percentage']."";
and here php totals each column...the third part of code wrong have far:
<?php $sql = "select round(avg(valuations),0) value_sum office_figures2016"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo "<td> " . $row["value_sum"]."</td>"; $sql = "select round(avg(instructions),0) value_sum office_figures2016"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo "<td> " . $row["value_sum"]."</td>"; // need divide total valuations total instructions x 100 = % // somehow need combine value sums together.. if? $sql = "select round(avg(''),0) value_sum office_figures2016"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo "<td> " . $row["value_sum"]."</td>";
i redid formula divide instructions , valuations in table x100 = %.
$sql = "select round(avg(instructions / valuations *100 ),0) value_sum office_figures2016";
$result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo "<td> " . $row["value_sum"]."</td>";
Comments
Post a Comment