multidimensional associatve array problem

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

from a MySQL DB i want to get a multidimensional array  that i can loop

either key =field name  value = array of ENUM options
or array[x][0] =field name,  array[x][1]= ENUM options and increment x
inside loop

$q=mysql_query("SHOW FIELDS FROM table"   ) or die ("Query failed");

while ($row = mysql_fetch_array($q))

echo 'field is '.$row['Field'] . '  type is  ' . $row['Type'];
if (ereg('enum.(.*).', $row['Field'], $match))
$opts = explode(',', $match[1]);
           foreach ($opts as $item)
               {$finalResult[] = substr($item, 1, strlen($item)-2);}

$array=array ($row['Field'] =>$finalResult[]);

gives Fatal error :Cannot use [] for reading in .......

a similar error message when i try a multidimentional array

anyone know the answer ( or a better way of doing it )

Re: multidimensional associatve array problem

pauld ( decided we needed to hear...
Quoted text here. Click to load it
<snip failing code>
Quoted text here. Click to load it
Try the following instead (altered from your code)...

$q = mysql_query("show fields from thetable");
$arr = array();
while ($row = mysql_fetch_array($q)) {
  echo 'field is ' . $row[0] . ' type is ' . $row[1] . '<br>';
  $finalResult = array();
  if (preg_match('/enum\((.*?)\)/', $row[1], $match)) {
    $opts = explode(',', $match[1]);
    foreach ($opts as $item) {
      array_push($finalResult, substr($item, 1, strlen($item)-2));
  $arr[$row[0]] = $finalResult;

(Remove REMOVE for email address)

Site Timeline