Results 1 to 18 of 18
Thread: Percentage in mysql query
Dec 2, 2009, 08:08 #1
- Join Date
- Dec 2009
- 0 Post(s)
- 0 Thread(s)
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:
$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'];
<table> <tr> <td> <?php echo "$bbcount1"; ?> </td> <td> <?php echo "$bbcount0"; ?> </td> <td> <?php echo "$bbcount2"; ?> </td> </tr> </table>