I have a sql server table, VATTable like this:
VatCode | VATRate | Description | Active
00 0 VAT Rate 0.00% 1
04 4 VAT Rate 4.00% 1
06 6 VAT Rate 6.00% 1
...
21 21 VAT Rate 21.00% 1
....
with this query
$query = "SELECT VatCode, VatRate, Description, 0 as Goods, 0 as eFees, 0 as pFees, 0 as sFees, 0 as VAT, 0 as Total from VATTable where active=1";
$result = sqlsrv_query($conn,$query);
I need to build a multidimensional array with such data, that looks like this:
$VATTable = array
(
'04'=> array(
'VATRate'=>'4',
'Desc'=>'VAT 4.00%',
'Goods'=>0,
'eFees'=>0,
'pFees'=>0,
'sFees'=>0,
'Taxable'=>0,
'VAT'=>0,
'Total'=>0
),
'06'=> array(
'VATRate'=>'06',
'Desc'=>'VAT 6.00%',
'Goods'=>0,
'eFees'=>0,
'pFees'=>0,
'sFees'=>0,
'Taxable'=>0,
'VAT'=>0,
'Total'=>0
),
'10'=> array(
'VATRate'=>'10',
'Desc'=>'VAT 10.00%',
'Goods'=>0,
'eFees'=>0,
'pFees'=>0,
'sFees'=>0,
'Taxable'=>0,
'VAT'=>0,
'Total'=>0
)
);
so to be able to manage it in the following way:
$vatCode='10';
$VATTable[$vatCode]['Goods']=15;
echo $VATTable[$vatCode]['Desc'].': '.$VATTable[$vatCode]['Goods'];
although my php knowledge is poor I think I have first to build the inner array and then use array_push to add to VATTable Array, but while searching for such solution, I found some example where I understood (??) that perhaps this can be done while fetching the recordset, and I thought I could do in this way: $VATTable = array();
while($row = sqlsrv_fetch_array($result))
{
$VATTable[$row['VATCode']]['VATRate']=$row['VATRate'];
$VATTable[$row['VATCode']]['Desc']=$row['Description'];
$VATTable[$row['VATCode']]['Goods']=$row['Goods'];
};
but it does not work.
can suggest solution?
Thanks