Percentage in mysql query
Okay, so I am a newbie to php and mysql. I will try to explain what I am trying to accomplish as best I can. I have a table with the following fields: wireGauge, time, fracture and other fields not used in this query. The fracture field stores the fracture point each time a record is added. There are 3 types of fracture points: anchor bend, break back and weld. What I am trying to do is figure out the percentage for each fracture point for a given wireGauge (such as 3, there are 4 different wireGauges: 2, 3, 4 and 4.5). I also want the user to be able to select the range of time from which to generate this report. So if there are 20 records I want to write a query that figures out the percentage of anchor bends, the percentage of break backs and the percentage of welds between a chosen time period for a given wireGauge such as 3. Once I have written the query I also need to figure out how to display the percentages in a table using php.
I have attached a screenshot of my table.
So far I have written the following:
To print the percentages later on the page I have the following inside a table:
$sql="SELECT fracture, COUNT(*)
WHERE time between '$time1' and '$time2'
AND wireGauge = '3'
GROUP BY fracture";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
while($row = mysql_fetch_assoc($result))
$bbcount0 = $row['fracture'];
$bbcount1 = $row['fracture'];
$bbcount2 = $row['fracture'];
Thanks for any help to understand and solve this.
<?php echo "$bbcount1"; ?>
<?php echo "$bbcount0"; ?>
<?php echo "$bbcount2"; ?>