I am trying to loop through some database results to build an array similar
to:
Array (
[33]=>Array (
[usa]=>52.00
[sa]=>553.00
)
)
And the problem that I am having is that array_push does not want to take
keys when I am using it.
$res=mysql_query("select distinct dealercode from transactions order by dealercode",$intranet);
$transactions=Array();
while($row=mysql_fetch_array($res)) {
$amt=mysql_query("select sum(amount) as total from transactions where date between '2003-04-01' and '2003-06-31' and dealercode='$row[dealercode]'",$intranet);
$afftotal=mysql_fetch_array($amt);
array_push($transactions,$row[dealercode]=>Array("onlineu",$afftotal[total]));
$amt=mysql_query("select usercountry,sum(amount) as total from orders_placed where date between '2003-04-01' and '2003-06-31' and dealercode='$row[dealercode]' and sent='y' group by usercountry",$intranet);
while($cdtotal=mysql_fetch_array($amt)) {
array_push($transactions[$row[dealercode]],$cdtotal[usercountry]=>$cdtotal[total]);
}
}
That should create the array above, but as I mentioned array_push does not
seem to be taking the keys.... I just get a Parse error message for the
line. (the first array_push)
Is this is 'bug' (I hate to assume just because I cannot get it to work that
it is a bug 😉 ) or am I trying to do something that is better accomplished
with another function?
I already know the following:
1. Yes I know that this can be done in 1 query - but due to the amt of data the query takes too long - the above is shorter believe it or not to return the data
2. I also know that the database structure can be improved, and will, but it is an inherited structure, and I do not have the time to change it before the report that this generates is needed.
The core of the question is:
Does array_push accept key=>value settings and this is a bug, or does array_push NOT accept key=>value settings and I should just try to get the values out a different way?
TIA