Multi Dimensional Arrays
Posted: Thu Feb 20, 2003 11:08 am
Kind of new to PHP, have moved from ASP.
My question is I am trying to put the results of a query on a mySQL database into a multi dimensional array but having no success!
My Code.....
<?php
require ('conn.php');
$MYSQL = mysql_query("SELECT * FROM Cost order by CostID Asc");
$RS = mysql_fetch_array($MYSQL,MYSQL_ASSOC);
$i = 0;
while ($RS = mysql_fetch_array($MYSQL,MYSQL_ASSOC))
{
$CostArray = array(
i => array($RS{'CostID'},$RS{'CostName'},$RS{'CostType'},$RS{'CostPrice'})
);
$i++;
}
print_r($CostArray);
?>
I am trying to create an array so I can call each element as:
$CostArray[0][0]
$CostArray[0][1] etc...
Please help.
Tx
My question is I am trying to put the results of a query on a mySQL database into a multi dimensional array but having no success!
My Code.....
<?php
require ('conn.php');
$MYSQL = mysql_query("SELECT * FROM Cost order by CostID Asc");
$RS = mysql_fetch_array($MYSQL,MYSQL_ASSOC);
$i = 0;
while ($RS = mysql_fetch_array($MYSQL,MYSQL_ASSOC))
{
$CostArray = array(
i => array($RS{'CostID'},$RS{'CostName'},$RS{'CostType'},$RS{'CostPrice'})
);
$i++;
}
print_r($CostArray);
?>
I am trying to create an array so I can call each element as:
$CostArray[0][0]
$CostArray[0][1] etc...
Please help.
Tx