Jump to content


Photo

Array accessed as table name, not number?


  • Please log in to reply
1 reply to this topic

#1 AncientSage

AncientSage
  • Members
  • PipPipPip
  • Advanced Member
  • 56 posts

Posted 18 September 2006 - 08:06 PM

Currently, I'm messing around with DBAL (Database Abstraction Layer), so I can't use MySQL functions and such. Anyway, I have this:

$sql = "SELECT id, name, info FROM forums";
$result = $dbh->query($sql);
$forums = array();
while($row = $result->fetchRow())
{
$forums[] = $row;
}

'k, that works. Now, I don't want to access the id field by going like this: $forums[0][0]

...which returns the first row and the first field. I want to be able to go and do this: $forums[id]

However, I'm not sure if it's possible or not, and again, I'm using a DBAL. Thanks.

#2 AncientSage

AncientSage
  • Members
  • PipPipPip
  • Advanced Member
  • 56 posts

Posted 18 September 2006 - 08:28 PM

Cancel that...
Seems I needed to set a mode for fetchRow(DB_FETCHMODE_OBJECT). Then foreach through the rows.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users