RE: [PHP-DB] Re: Dumping MySQL rows into a 2D array
| From: | George Pitcher | Date: | Fri, 13 Dec 2002 15:29:57 +0000 |
| Subject: | RE: [PHP-DB] Re: Dumping MySQL rows into a 2D array | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-24126@lists.php.net to get a copy of this message | ||
Bastian,
That's great - it does the trick perfectly. Many thanks.
George
> -----Original Message-----
> From: Bastian Vogt [mailto:bastian.vogt@komtel.net]
> Sent: 13 December 2002 3:18 pm
> To: php-db@lists.php.net
> Subject: [PHP-DB] Re: Dumping MySQL rows into a 2D array
>
>
> Hi,
>
> first leave out the loop with "for ($i...)".
> then use the loop with "while" and make sure that you create
> arrays. you're
> currently filling the same variables with different results each
> time. the last
> one always overwrites the ones bevor.
> so add those brackets: []:
> $dbRow['ev_id'][] = $row["id"];
> $dbRow['ev_uid'][] = $row["user_id"];
> ....
>
>
> HTH,
> Bastian
>
> George Pitcher schrieb:
>
> > Hi all,
> >
> > I want to grab the resul from a db query and store it in an
> array so that I
> > can selectively grab the data later.
> >
> > This is what I'm doing:
> >
> > $dbRowCount = mysql_num_rows( $result );
> > for ($i = 1; $i <= $dbRowCount; ++$i) {
> > while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
> > $dbRow['ev_id'] = $row["id"];
> > $dbRow['ev_uid'] = $row["user_id"];
> > $dbRow['ev_title'] = $row["name"];
> > $dbRow['ev_cat'] = $row["category"];
> > $dbRow['ev_sd'] = $row["start_day"];
> > $dbRow['ev_ed'] = $row["end_day"];
> > }
> > }
> >
> > In my sample database, I have two records which are both found with the
> > query (tested in MySQLFront) but the array ends up with 3 rows
> each with the
> > last record in it.
> >
> > Any suggestions?
> >
> > George
> >
> > ===
> >
> > George Pitcher
> > HERON Technical Manager
> > Ingenta plc
> > 23-38 Hythe Bridge Street, Oxford, OX1 2ET
> > T +44 (0)1865 799137 direct
> > T +44 (0)1865 799000 switchboard
> > F +44 (0)1865 799134
> > E george.pitcher@ingenta.com
> >
> > www.ingenta.com
> > Ingenta: Empowering the exchange of academic and professional content
> > online.
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>