zero-perfoliate
zero-perfoliate

Author Topic: Formatt Help on a few functions and arrays.  (Read 195 times)

Offline butsags

  • New PHP Members
  • Posts: 2
  • Karma: +0/-0
Formatt Help on a few functions and arrays.
« on: August 17, 2010, 08:36:31 PM »
Hey guys!

So I'm trying to update a pie chart type flash object that reads off a xml file that is built via php.

I came in on the project when it was pre-built. all the usernames were hand coded in and my boss simply wants me to make it dynamic and draw all users where show on pie chart =1.

simple enough right?

Ok so there are 3 main functions of data:
1: the names
2: the colors to go with the names
3: the calculated number for each name which will slice the pie accordingly and proportionalized.

Here's how the original code looked and is working 100%:
Code: [Select]
<?php
session_start
();
include_once(
"../zero/functions_v2.php");
function 
getGrossSalesByTimeframeAndSalesman($salesman$start_date$end_date)
{
$gross 0;
$query "select * from order_log where salesman='$salesman' and log_date >= '$start_date' and log_date < '$end_date'";

$dbh mysql_connect(MYSQLHOST,MYSQLLOGINMYSQLPASSWD) or die ("erreur  : ".mysql_error());
$db mysql_select_db("cbs_db1",$dbh);
$result mysql_query($query);
while ($row mysql_fetch_assoc($result))
$gross += $row["gross"];
return $gross

}
$dict $_SESSION[phase];
$phase getBracketDatesFromPhase($dictdate("Y"));
$ar explode($phase"|");
$ar explode("|"$phase);
$day0 $ar[0]; 
$dayF $ar[1];
$chart 'chart_type' ] = "3d pie";

$chart 'series_color' ] = array("17bd38""fbd100""3b66bd""ce404e""651ad5""d55900""8C985F""689872""bd8294""eaea49""000000""bd5b3b");
$chart['chart_value' ] = array ( 'position' => "cursor",
 'separator' => ",",
 'prefix' => "$"
);
$chart'chart_data' ] = array( array( ""AlanMatthew,  DeborahVeronicaWalterReneeFrankPamelaElizabethInternet),
array( 0getGrossSalesByTimeframeAndSalesman("aadler"$day0$dayF),
getGrossSalesByTimeframeAndSalesman("madler"$day0$dayF),  
getGrossSalesByTimeframeAndSalesman("ddellavechia"$day0$dayF),
getGrossSalesByTimeframeAndSalesman("vknipping"$day0$dayF),
getGrossSalesByTimeframeAndSalesman("wbarker"$day0$dayF),
getGrossSalesByTimeframeAndSalesman("rgordon"$day0$dayF),  
getGrossSalesByTimeframeAndSalesman("ftaylor"$day0$dayF),
getGrossSalesByTimeframeAndSalesman("ppena"$day0$dayF),
getGrossSalesByTimeframeAndSalesman("ebrandt"$day0$dayF),
getGrossSalesByTimeframeAndSalesman("internet"$day0$dayF)));

SendChartData $chart );

?>







and here's what i have so far in the updated dynamic code:
(Remember, the getColors() and the getNames() functions work perfectly, its when the getGrossSalesByTimeframeAndSalesman() function comes in that the code is thrown off)

Code: [Select]
<?php
session_start
();
include_once(
"../zero/functions_v2.php");
$dict $_SESSION[phase];
$phase getBracketDatesFromPhase($dictdate("Y"));
$ar explode($phase"|");
$ar explode("|"$phase);
$day0 $ar[0]; 
$dayF $ar[1];
function 
getGrossSalesByTimeframeAndSalesman($salesman$start_date$end_date)
{
$gross 0;
$query "select * from order_log where salesman='$salesman' and log_date >= '$start_date' and log_date < '$end_date'";

$dbh mysql_connect(MYSQLHOST,MYSQLLOGINMYSQLPASSWD) or die ("erreur  : ".mysql_error());
$db mysql_select_db("cbs_db1",$dbh);
$result mysql_query($query);
while ($row mysql_fetch_assoc($result))
$gross += $row["gross"];
return $gross

}
function 
getColors(){
$dbh mysql_connect(MYSQLHOST,MYSQLLOGINMYSQLPASSWD) or die ("erreur  : ".mysql_error());
$db mysql_select_db("cbs_db1",$dbh);
$result mysql_query("select * from `users` where `s_pie_chart` = '1' order by `username` asc");
$arr = array();
while ($row mysql_fetch_assoc($result))
array_push($arr$row["pie_chart_color"]);
return $arr;
}

function 
getNames(){
$dbh mysql_connect(MYSQLHOST,MYSQLLOGINMYSQLPASSWD) or die ("erreur  : ".mysql_error());
$db mysql_select_db("cbs_db1",$dbh);
$result mysql_query("select * from `users` where `s_pie_chart` = '1' order by `username` asc");
$arr = array();
while ($row mysql_fetch_assoc($result))
array_push($arr$row["first_name"]);
return $arr;
}

function 
getCode(){
$dbh mysql_connect(MYSQLHOST,MYSQLLOGINMYSQLPASSWD) or die ("erreur  : ".mysql_error());
$db mysql_select_db("cbs_db1",$dbh);
$result mysql_query("select * from `users` where `s_pie_chart` = '1' order by `username` asc");
$arr = array();
while ($row mysql_fetch_assoc($result)){
$action getGrossSalesByTimeframeAndSalesman($row["username"], $day0$dayF);
array_push($action);
}
return $arr;
}
$chart 'chart_type' ] = "3d pie";
$chart 'series_color' ] = getColors();
$chart['chart_value' ] = array ( 'position' => "cursor",
 'separator' => ",",
 'prefix' => "$"
);
$chart'chart_data' ] = array( 
getNames(),
getCode()
);

SendChartData $chart );

?>