moondance
02-11-2004, 11:36 AM
i'm developing a simple class that will return to the user a multidimensional array from a user-defined sql statement.
i'm using the array_fill function, and it seems to be populating it ok, but i'm not sure what loops to use to display it - i want to use the database fields for the key, and the id as the array name, so for instance the following array structure:
$result = array (
"1"=>array(
"Fname"=>"John",
"Sname"=>"Doe",
"DOB"=>"07-02-1970"
)
"2"=>array(
"Fname"=>"Joe",
"Sname"=>"Bloggs",
"DOB"=>"16-10-1990"
)
)
I had used the following code to traverse the array to display each element:
echo "<table border = \"1\" width = \"25%\">";
while (list($key, $item) = each ($result))
{
echo "<tr><td>$key</td><td>$item</td></tr>";
}
echo "<table>";
...but all it says is "Array" for the amount of arrays in it.
Any ideas?
:confused:
i'm using the array_fill function, and it seems to be populating it ok, but i'm not sure what loops to use to display it - i want to use the database fields for the key, and the id as the array name, so for instance the following array structure:
$result = array (
"1"=>array(
"Fname"=>"John",
"Sname"=>"Doe",
"DOB"=>"07-02-1970"
)
"2"=>array(
"Fname"=>"Joe",
"Sname"=>"Bloggs",
"DOB"=>"16-10-1990"
)
)
I had used the following code to traverse the array to display each element:
echo "<table border = \"1\" width = \"25%\">";
while (list($key, $item) = each ($result))
{
echo "<tr><td>$key</td><td>$item</td></tr>";
}
echo "<table>";
...but all it says is "Array" for the amount of arrays in it.
Any ideas?
:confused: