Jump to content

[SOLVED] Creating multi-dimensional arrays in a loop


Doug_M

Recommended Posts

Hi,

 

I'm trying to create a multi-dimensional array from the results of an MDB2 query.  All the examples I can find have the array "hard-coded" so to speak and so are not helpful.  Here's what I have:

 

// perform query
$result = $mdb2->query($sql);

// get results
if ($result != null)
{
// build app array
while ($row = $result->fetchRow())
{
	$apps[] = array(array($row[0], $row[1], $row[2]));
}
}

 

Of course this doesn't work.  The brackets on $apps work for a single-dimension array.  I've tried two sets of brackets but that's not right either.

 

Regards,

Doug

// perform query
$result = $mdb2->query($sql);

$apps = array();
// get results
if ($result != null)
{
   // build app array
   while ($row = $result->fetchRow())
   {
      $apps[] = $row;
   }

   print_r($apps);
}

 

Should produce a multi-dimensional array.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.