I've tried a bunch of examples and methodologies out there but keep running into the same issue. The function I built to build the array does not work as a function (will not return the array), only when it is run buy itself. The array builds and outputs fine if run w/o being inside a function.
here's my code. Booleans debug and resultOutput are for triggering output.
<?php
//require('includes/html_table.class.php');
require_once "php/mysql.php";
require('includes/fx.php');
$debug=FALSE;
//////////////////
// DEBUG TOGGLE //
$debug = TRUE;//
//////////////////
//////////////////
// RESULT PRINT TOGGLE //
$resultOutput = TRUE;//
//////////////////
//variables
$starttime = microtime(true); //stopwatch
//all important tea off date is set below
function makeReport(){
$youngest='2015-9-21 23:59:59';
//$youngest = $startDate;
$youngest = strtotime($youngest);
$oldest=$youngest-2505600; //to figure out what plans the customer is using in the past 30 days
$arrayCompPlans = array();
$seqint=0; //for navigating arrays
$regBusHours=TRUE;
//if we want to start only looking at m-f use this code
//will be put in a function for production
$count=0; //total weekdays polled
for($x=0; $x <= 29; $x++)
{
if($regBusHours){
$day1 = strtotime("-$x day",$youngest);
$day2 = strtotime('-1 day',$day1);
if (!isweekend($day1))
{
$count=1+$count;
}
}
else $count=30;
}
echo $count;
$SQL = "SELECT *
,(PlanMinUsage/$count) AS AvgDailyUsage
,(PlanMinLimit-PlanMinUsage) AS RemainingMins
FROM (
SELECT b.company Company
, a.subid CompanyID
, c.description Plan
, a.planid PlanID
, c.monthlymins PlanMinLimit
, count(a.planid) PlanCalls
, sum(a.minsused) PlanMinUsage
FROM transactions a
INNER JOIN subscribers b
ON a.subid=b.subid
INNER JOIN plans c
ON a.planid=c.id
WHERE (a.timestamp>=1440388799 AND a.timestamp<=1442894399)
AND planid!='0'
GROUP BY a.subid,a.planid) as subQ";
debugOutStr($SQL,$debug);
$theRES = mysql_query($SQL, $db);
$seqint=0;
while($row=mysql_fetch_assoc($theRES))
{
$arrayCompPlans[]=$row;
}
print_r($arrayCompPlans);
return $arrayCompPlans;
}
$array = makeReport();
print_r($array);
$endtime = microtime(true);
$tottime=number_format(($endtime-$starttime),2,'.',',');
if($resultOutput){
debugOutStr(("<br>Total Run Time: ".$tottime." seconds<br>"),$resultOutput);
debugOutArray($array, $resultOutput);
}
when attempting to echo the function only the count echo's out, array comes back empty.