[SOLVED] Using arrays to build a graphic...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
paolone
Forum Commoner
Posts: 37
Joined: Tue Jun 11, 2002 10:18 am

[SOLVED] Using arrays to build a graphic...

Post by paolone »

Hello all,

i'm trying to build a chart using "panachart" as the renderinig script, and what i'm trying to do is to fill the array values from a database. but with no success... :cry:

the chart should show the "days of the week" in the X bar, the "Response time" in the Y bar, and with values i will generate the lines for the chart to display. there are 3 lines to be generated, that are fix, and coming from the result of the MySQL database.

I run the following query to retrive the values :



The problem is the following :

In the panachart script i need to have 3 arrays : One for the values,

Code: Select all

$sql = "
SELECT avg(  `transaction_response_time`  ) ,  `theDate` , Left(  `search_opt` , 17  )  AS trans
FROM  `kpi` 
WHERE (  ".$_REQUEST['period']." ) AND  `transaction_response_time`  !=  '++++++++'
GROUP  BY  `trans` ,  `theDate` 
ORDER  BY  `theDate`  ASC
";
if i print the result with

Code: Select all

if ($_POST['Submit']){
	while ($res_data = mysql_fetch_array($results)) 
		{
		print_r($res_data);
		}
i get :

Code: Select all

Array
(
    [0] => 2.0351984732824
    [avg(  `transaction_response_time`  )] => 2.0351984732824
    [1] => 2005-09-12
    [theDate] => 2005-09-12
    [2] => Transaction OPSea
    [trans] => Transaction OPSea
)
Array
(
    [0] => 2.7655852272727
    [avg(  `transaction_response_time`  )] => 2.7655852272727
    [1] => 2005-09-12
    [theDate] => 2005-09-12
    [2] => Transaction Login
    [trans] => Transaction Login
)
Array
(
    [0] => 5.334
    [avg(  `transaction_response_time`  )] => 5.334
    [1] => 2005-09-12
    [theDate] => 2005-09-12
    [2] => Transaction Selec
    [trans] => Transaction Selec
)
Array
(
    [0] => 5.4144186046512
    [avg(  `transaction_response_time`  )] => 5.4144186046512
    [1] => 2005-09-13
    [theDate] => 2005-09-13
    [2] => Transaction Selec
    [trans] => Transaction Selec
)
Array
(
    [0] => 1.9378790322581
    [avg(  `transaction_response_time`  )] => 1.9378790322581
    [1] => 2005-09-13
    [theDate] => 2005-09-13
    [2] => Transaction OPSea
    [trans] => Transaction OPSea
)
Array
(
    [0] => 3.6729545454545
    [avg(  `transaction_response_time`  )] => 3.6729545454545
    [1] => 2005-09-13
    [theDate] => 2005-09-13
    [2] => Transaction Login
    [trans] => Transaction Login
)
Array
(
    [0] => 3.4138620689655
    [avg(  `transaction_response_time`  )] => 3.4138620689655
    [1] => 2005-09-14
    [theDate] => 2005-09-14
    [2] => Transaction Login
    [trans] => Transaction Login
)
Array
(
    [0] => 5.7533181818182
    [avg(  `transaction_response_time`  )] => 5.7533181818182
    [1] => 2005-09-14
    [theDate] => 2005-09-14
    [2] => Transaction Selec
    [trans] => Transaction Selec
)
Array
(
    [0] => 1.9585230769231
    [avg(  `transaction_response_time`  )] => 1.9585230769231
    [1] => 2005-09-14
    [theDate] => 2005-09-14
    [2] => Transaction OPSea
    [trans] => Transaction OPSea
)
Array
(
    [0] => 5.3420454545455
    [avg(  `transaction_response_time`  )] => 5.3420454545455
    [1] => 2005-09-15
    [theDate] => 2005-09-15
    [2] => Transaction Selec
    [trans] => Transaction Selec
)
Array
(
    [0] => 2.0540839694656
    [avg(  `transaction_response_time`  )] => 2.0540839694656
    [1] => 2005-09-15
    [theDate] => 2005-09-15
    [2] => Transaction OPSea
    [trans] => Transaction OPSea
)
Array
(
    [0] => 2.3190454545455
    [avg(  `transaction_response_time`  )] => 2.3190454545455
    [1] => 2005-09-15
    [theDate] => 2005-09-15
    [2] => Transaction Login
    [trans] => Transaction Login
)
Array
(
    [0] => 1.7000991735537
    [avg(  `transaction_response_time`  )] => 1.7000991735537
    [1] => 2005-09-16
    [theDate] => 2005-09-16
    [2] => Transaction OPSea
    [trans] => Transaction OPSea
)
Array
(
    [0] => 2.8664197530864
    [avg(  `transaction_response_time`  )] => 2.8664197530864
    [1] => 2005-09-16
    [theDate] => 2005-09-16
    [2] => Transaction Login
    [trans] => Transaction Login
)
Array
(
    [0] => 5.1522195121951
    [avg(  `transaction_response_time`  )] => 5.1522195121951
    [1] => 2005-09-16
    [theDate] => 2005-09-16
    [2] => Transaction Selec
    [trans] => Transaction Selec
)
Now my problem is to retrive from this results the arrays i need... as specified above. One with "average response time", one with "the date" and one with the "transaction name". possibly, this last one, the transactin name, should be splitted in the 3 different one, "transaction login", "transaction Selec", "transaction OPsea"

What is the step to do?

Thanks all for your contribution...
Last edited by paolone on Thu Sep 29, 2005 9:54 am, edited 1 time in total.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

Code: Select all

<?php

function sqlClean ($string) {
    if (get_magic_quotes_gpc()) {
        $string = stripslashes($string);
    }
    return mysql_real_escape_string($string);
}

$sql = "
SELECT avg(  `transaction_response_time`  )  as avgresptime,  `theDate` , Left(  `search_opt` , 17  )  AS trans
FROM  `kpi`
WHERE (  ".$_REQUEST['period']." ) AND  `transaction_response_time`  !=  '++++++++'
GROUP  BY  `trans` ,  `theDate`
ORDER  BY  `theDate`  ASC
";
        

$date = array();
$avg_resp_time = array();
$tran_name = array();

while ($row = mysql_fetch_assoc($result)) {
    $date[] = $row['theDate'];
    $avg_res_time[] = $row['avgresptime'];
    $tran_name[] = $row['trans'];
}

?>
HTH.. :)
paolone
Forum Commoner
Posts: 37
Joined: Tue Jun 11, 2002 10:18 am

Post by paolone »

Thanks a lot...
this solved my problem, that was more like a "lack" of skills...
never stop learning in life... :oops: :P
Post Reply