Help with determining the percentage of values [Solved]
Posted: Tue Nov 11, 2003 6:45 pm
Right now, I'm pulling information from a database. In this database is a column named PACKETS.
Right now, I'm sorting the table PER HOUR and posting the results of the amount of packets sent. However, I am also wanting to post the results of each query into a pie char, but in order to do that, I need to determine the overall percentage of bandwidth sent within each hour
In other words, let's say i have 5 different hours ( 1pm, 2pm, 3pm, 4pm, 5pm ).
between the hours 1pm and 2pm, 500000 packets are sent. between the hours 3pm and 4pm 30000 packets are sent, and between the hours of 4pm and 5pm 1000000 packets are sent.
What I would like to do , is say 30% of all packets sent was between the hours of 1pm and 2pm. 20% of all packets sent was between the horus 3pm and 4pm, and 50% of all packets sent was between the hours of 4pm and 5pm.
i know those percentages i just gave are incorrect, but it's just to give you an idea. perhaps there is a way to do this within my existing sql statement, or maybe i ahve to do it after the values are sorted out in my while loop.
Here is the code i'm using :
currently, my output looks like this :
I posted this here because i'm sure if it's a php mathematical formula that i need to write, or if it's just a mysql query i need to put.
If you'd rather not write out the answer and just have links I could look at, i'd appreciate that more then the answer because it helps me to learn php when i do it on my own ( well, after a little kick to get me started with some functions to peek at
)
Thanks
Right now, I'm sorting the table PER HOUR and posting the results of the amount of packets sent. However, I am also wanting to post the results of each query into a pie char, but in order to do that, I need to determine the overall percentage of bandwidth sent within each hour
In other words, let's say i have 5 different hours ( 1pm, 2pm, 3pm, 4pm, 5pm ).
between the hours 1pm and 2pm, 500000 packets are sent. between the hours 3pm and 4pm 30000 packets are sent, and between the hours of 4pm and 5pm 1000000 packets are sent.
What I would like to do , is say 30% of all packets sent was between the hours of 1pm and 2pm. 20% of all packets sent was between the horus 3pm and 4pm, and 50% of all packets sent was between the hours of 4pm and 5pm.
i know those percentages i just gave are incorrect, but it's just to give you an idea. perhaps there is a way to do this within my existing sql statement, or maybe i ahve to do it after the values are sorted out in my while loop.
Here is the code i'm using :
Code: Select all
<?php
@mysql_pconnect ('localhost','username','password');
mysql_select_db ('logparser');
$sql = "select avg(packets), hour(time) FROM log group by hour(time) order by hour(time) desc";
$result = mysql_query($sql) or die(MySQL_Error());
$num_results = mysql_num_rows($result);
$row = mysql_fetch_assoc($result);
mysql_data_seek ($result, 0);
echo '<strong><p>';
while ($row = mysql_fetch_assoc ($result))
{
echo 'Time : ';
echo $row['hour(time)'];
echo '<br />';
echo 'Average Packets : <br />';
echo $row['avg(packets)'];
echo '<br /> <br />';
}
echo '</strong></p>';
?>currently, my output looks like this :
Code: Select all
Time : 13:00
Average Packets Sent :
44791.8481
Time : 12:00
Average Packets Sent :
45299.2857
Time : 11:00
Average Packets Sent :
146491.0714
Time : 10:00
Average Packets Sent :
16788.0000
Time : 09:00
Average Packets Sent :
349418.0000
Time : 07:00
Average Packets Sent :
95160.0000
Time : 06:00
Average Packets Sent :
20644.0882
Time : 05:00
Average Packets Sent :
24776.0968
Time : 04:00
Average Packets Sent :
36942.5625I posted this here because i'm sure if it's a php mathematical formula that i need to write, or if it's just a mysql query i need to put.
If you'd rather not write out the answer and just have links I could look at, i'd appreciate that more then the answer because it helps me to learn php when i do it on my own ( well, after a little kick to get me started with some functions to peek at
Thanks