2

I'm creating a table using a PHP from the MySQL query which return a total count of rows from two columns in the database, "total_tr" and "total_rc".

I've already done and successfully view the count in the PHP table, the coding is:

 while($row = mysql_fetch_array($result))
      {
            echo "<tbody>";
              echo "<tr>";
                  echo "<td>Zone</td>";
                  echo "<td>" . $row['segment_code'] . "</td>";
                  echo "<td>" . $row['COUNT(total_tr)'] . "</td>";
                  echo "<td>" . $row['COUNT(repeat_rc)'] . "</td>";
              echo "</tr>";
            echo  "</tbody>"; 
      }  

My problem now is, I want to take the total count value of "total_tr", divided with total count of "repeat_rc" and multiply with 100 to get the percentage of total_rc.

Any ideas on how can I do that?

2 Answers 2

1
$myresult = $row['COUNT(total_tr)'] / $row['COUNT(repeat_rc)'] * 100;
Sign up to request clarification or add additional context in comments.

1 Comment

I'm glad I could help
0

Keep a running count as you echo the rows

$total_tr = 0;
$total_rc = 0;
while($row = ...) {
    $total_tr += $row['COUNT(total_tr)']);
    $total_rc += $row['COUNT(repeat_rc)']);
    ... html here ...
}
echo $total_tr / $total_rc * 100;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.