Creating a recallable array from Query Result?
Posted: Fri Nov 14, 2003 9:22 pm
Hi again. I'm trying to figure this one out, but it's got me stumped. What I have is a query statement that is calling a GROUP BY statement, and dumbing the rows out. What I want to do, is query both the PACKETS and the TIME it goes along with in 2 seperate arrays, that I can calll later to compare to static arrays in order to post them into a Bar Graph..
Best way to show you what I mean is by examples of my code, so here goes :
now, i did find a lot of different opinions on how to do this with phpBuilder, and google, but none seem to work the way i need it to...
one thing that i found that was almost it, was
but, i have no way of knowing how to extract each array, compare it to the static array, and then be able to put the correct packet amounts with the corresponding time array 
Right now, the bar chart is doing stuff like this to me :
so basically, i need a way to be able to search the dynamically generated arrays from my SQL statement, and match each array with the corresponding static array, and THEN match that resulting array with the packet array... fun huh? well, i've almost given myself a concussion from banging my head so many times on my desk from this hairy situation, but hey I'm trying
lol, i know this may have been long and drawn out, but I feel i have to explain myself as best as I can so i can give you all some sort of idea of what i'm doing, and what direction i'm going. at least then maybe someone can see what i'm doing wrong, and point me in the correct direction.
Best way to show you what I mean is by examples of my code, so here goes :
Code: Select all
<?php
###############################################
# I created a static array here because what I wanted to do is be able to
# set an array to the possible results of hour(time). The reason is, when
# you post your results to a chart based on the below query, it will ONLY
# post the results of times that have packet values, and then it will just
# skip the ones it has posted, and then post the other empty times,
# leaving the chart very unorganized. i'll give an example of the chart
# after showing you the code.
###############################################
//Static Array that will be called to compare with results
$time = array('0','1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13','14','15','16','17','18','19','20','21','22','23');
@mysql_pconnect ('localhost','username','pass');
@mysql_select_db ('logparser');
###############################################
# Get a SUM of all Packets based on the HOUR in which they are stored
# in the database.
#
# Example :
# Time | Packets
# 04:00:44 | 393475
# 04:34:00 | 39344
# 10:00:44 | 348576
# 18:04:33 | 34848
#
# Would result in:
# Hour (4 to 5) - 432819 Total Packets
# Hour (10 to 11) - 348576
# Hour (18 to 19) - 34848
#
# I need to get each Hour found to have packets, and place it as an
# aray such as $found_time[4] = '4'; Packets[4] = '432819';
#
#
# however, when it DOES find a time, it assigns it to the very first array
# meaning, it would assign it to $found_time[0], and screw up being
# able to do something like If $time[4] == $found_time[4] then
# x = '04:00am', and then being able to match the packet array with
# that time found.. Anyways, here is the sql statement
###############################################
$sql="select sum(packets), hour(time) from log group by hour(time) order by time DESC";
$result = mysql_query($sql);
?>now, i did find a lot of different opinions on how to do this with phpBuilder, and google, but none seem to work the way i need it to...
one thing that i found that was almost it, was
Code: Select all
<?php
while( $t = mysql_fetch_row($result))
{
$array[] = $t;
}
?>Right now, the bar chart is doing stuff like this to me :
Code: Select all
800000 bytes
400000 bytes
200000 bytes
100000 bytes
|_____|____|___|_____________________
4 10 18 0 1 2 3 5 6 7so basically, i need a way to be able to search the dynamically generated arrays from my SQL statement, and match each array with the corresponding static array, and THEN match that resulting array with the packet array... fun huh? well, i've almost given myself a concussion from banging my head so many times on my desk from this hairy situation, but hey I'm trying
lol, i know this may have been long and drawn out, but I feel i have to explain myself as best as I can so i can give you all some sort of idea of what i'm doing, and what direction i'm going. at least then maybe someone can see what i'm doing wrong, and point me in the correct direction.