You are here: Re: [PHP] array help « PHP « IT news, forums, messages
Re: [PHP] array help

Posted by Robert Cummings on 10/21/58 11:21

Did you bother to initialize $table as an array() or are you another
lazy slob of a programmer that expects the engine to read your mind
(cluttered as that may be)?

Cheers,
Rob.

On Thu, 2005-07-14 at 18:33, Fletcher Mattox wrote:
> How does one represent a MySQL table as a two dimensional array
> using the column names as one of the indices? My naive attempt
> went something like this:
>
> while ($row = mysqli_fetch_assoc($result))
> $table[] = $row;
>
> but that generated this error;
>
> Fatal error: [] operator not supported for strings
>
> Ok. So then I try to explicitly assign each row, like this:
>
> while ($row = mysqli_fetch_assoc($result))
> $table[$i++] = $row;
>
> While that generates no error, $table contains nothing useful when
> I'm done. So then I try to assign each row and column, like this:
>
> while ($row = mysqli_fetch_assoc($result)) {
> foreach ( $row as $col => $val)
> $table[$i][$col] = $val;
> $i++;
> }
>
> And that got me this error:
>
> Fatal error: Cannot use string offset as an array
>
> So clearly my understanding of PHP arrays is lacking.
> Please help.
>
> Thanks
> Fletcher
--
..------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация