Hello peeps 🙂
I never was much good at maths, I'm trying to do something very easy, but for the life of me can not figure it out, so was wondering if someone could put me out of my pain!!
Here is my problem,
I'm building a feedback table,
There are 3 possible feedbacks, positive, negative, and neutral.
If someone leaves poisitive feedback, the number ' 1 ' is placed in the positive table.
If someone leaves negative feedback, the number ' 1 ' is placed in the negative table.
If someone leaves neutral feedback, the number ' 1 ' is placed in the neutral table.
So, if I had a total of 4 feedbacks, 2 positive, 1 negative and 1 Netural, I should get the figure 50% positive feedback received.... correct? 😕
// Get how many POSITIVE feedbacks have been left
$result = mysql_query("SELECT * FROM feedback WHERE drivernumber = '$DriverNo' AND positive = '1' ");
$totalpos = mysql_num_rows($result);
// Get how many NEGATIVE feedbacks have been left
$result = mysql_query("SELECT * FROM feedback WHERE drivernumber = '$DriverNo' AND negative = '1' ");
$totalneg = mysql_num_rows($result);
// Get how many NEUTRAL feedbacks have been left
$result = mysql_query("SELECT * FROM feedback WHERE drivernumber = '$DriverNo' AND neutral = '1' ");
$totalneut = mysql_num_rows($result);
// Get hot many TOTAL feedbacks have been left
$result = mysql_query("SELECT * FROM feedback WHERE drivernumber = '$DriverNo' ");
$totalfeedback = mysql_num_rows($result);
// Display the last 30 feedback for this driver.
$sql="select * from feedback WHERE drivernumber = '$DriverNo' ORDER BY `id_auto` DESC LIMIT 30";
echo "<table width=\"100%\" border=\"1\" bordercolor=\"#000080\">";
// DO THE MATHS HERE
$percent=$totalfeedback/$totalpos;
// END MATHS
echo "<center>Total Positive Feedback [ <b>$totalpos</b> ] | Total Negative Feedback [ <b>$totalneg</b> ] | Total Neutral Feedback [ <b>$totalneut</b> ] | Total Feedback [ <b>$totalfeedback</b> ] | $percent % Positive</center><br>";
From the code above, when I run the script, it outputs 2% positive, thus me thinks I'm making a silly error somewhere, as it should say 50% 😕