I'm trying to build a set of arrays based on MySQL field names in a table, then populate those arrays with information from the table itself. Everything seems to be in order until I attempt to populate the arrays (for ($i2 = 0, etc). The code below produces only two out of five arrays:
// loop through sections fields starting at 1 to skip the number field //
for ($i = 1; $i < $number_of_sections; ++$i) {
echo ("Setting up section " . $i . "... (");
// set temporary variable to hold name //
$this_section = mysql_field_name ($query, $i);
echo ($this_section . ")<br>\n");
// create an array with the section name //
$$this_section = array ();
// get the rows for $this_section //
$this_query = ("SELECT number FROM sections WHERE " . $this_section . "='t'");
$this_result = mysql_query ($this_query)
or die (mysql_error ());
$this_count = mysql_num_rows ($this_result);
echo ("Number of entries in " . $this_section . " = " . $this_count . "<br>\n");
for ($i2 = 0; $i2 < $this_count; ++$i2) {
$this_row = mysql_fetch_row ($this_result);
$$this_section[$i2] = $this_row[0];
}
echo ("Number of entries in " . $this_section . " = " . count ($$this_section) . "<br>\n");
foreach ($$this_section as $element) {
echo ($element);
}
}
You can take a look at the output I get with the above code at http://www.erobertwald.com/scripts/image_list.php
Any ideas?