Function dis-function
Posted: Fri Apr 20, 2007 4:00 am
Hiya,
I am having trouble accessing my array from within another function.
getDebtTop5() does not seem to able to access the array.
Can anyone see my error?
The output I see is just 'NULL'.
tia, will.
I am having trouble accessing my array from within another function.
getDebtTop5() does not seem to able to access the array.
Can anyone see my error?
The output I see is just 'NULL'.
tia, will.
Code: Select all
function getAllShops(){
global $linkID, $clientsID , $companyName, $shopArray;
$clientQuery = 'select id, company_name from clients';
$clientResult = mysql_query($clientQuery, $linkID) or die("Data not found.");
for($x = 0 ; $x < mysql_num_rows($clientResult) ; $x++){
$row = mysql_fetch_assoc($clientResult);
$shopArray[] = array($row['id'] => $row['company_name']);
}
return $shopArray;
}
function getTotals() {
global $linkID, $clientResult, $shopArray;
getAllShops($shopArray);
foreach ($shopArray as $outer_key => $single_array) {
foreach ($single_array as $inner_key => $value) {
$debtQuery = "select sum(total) as total from statements where client_id = '$inner_key'";
$debttResult = mysql_query($debtQuery, $linkID) or die("Data not found.");
for($x = 0 ; $x < mysql_num_rows($debttResult) ; $x++){
$row = mysql_fetch_assoc($debttResult);
}
}
$getTotalsArray[] = array($inner_key, $row['total']);
}
return $getTotalsArray;
}
function getDebtTop5() {
global $getTotalsArray;
getTotals($getTotalsArray);
echo "<hr><pre>";
var_dump($getTotalsArray);
echo "</pre>";
}