Hi,
This is my first real attempt at doing anything with PHP, so please be gentle if I'm missing something obvious with my problem...
I'm having trouble accessing the values I've stored in an array. I'm quering my database and creating a multidimensional array with XML tags based on the field names returned from the query.
If I attempt to print the values, I get exactly what I expect when printing from within the for loop that populates the array.
After the loop is finished and the array is populated, I get nothing when I attempt to access a value in the newly created array.
Can anyone point me in the right direction?
Thanks.
The code:
$result = mysql_query("select * from entries", $connection);
$fieldcount = mysql_num_fields($result);
$entriesXML = array();
while ($entries = mysql_fetch_array($result)) {
for($i=0; $i<$fieldcount; $i++) {
$fieldname = mysql_fieldname($result, $i);
$insertXML = '<'.$fieldname.'>'.$entries["$fieldname"].'</'.$fieldname.'>';
$entriesXML[$entries["id"]] = array("$fieldname"=>"$insertXML");
/**
This print statement produces the results I expect.
The result: <headline>Some Headline</headline>
*/
print $entriesXML[1]["headline"];
}
}
// this one does not print any results
print $entriesXML[1]["headline"];