Re: convert query result to array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



fetchAll() works if php version is greater than 5.

As Wang suggested, we should write our own function.
its easy... i have done so many times for larger database.

Store earch rows of the resultset in the array (multidimensional ie. 2). and
then work on the array using the loops & conditions

 $query = "select * from tablename";
$result = mysql_query($query);
while($arr = somefunction($result)){
$resultarray[] = $arr;
}

Hope it works!

On 5/13/08, Forcey <forcey@xxxxxxxxx> wrote:
>
> I guess PDOStatement::fetchAll() should work?
>
> see http://www.php.net/manual/en/pdostatement.fetchall.php for details.
>
>
> - Forcey
>
>
> On Tue, May 13, 2008 at 9:55 AM, Yi Wang <wangyi6854@xxxxxxxxx> wrote:
> > I think flance's meaning is whether there is a build-in function that
> >  can convert the result set to an array.
> >
> >  The short answer is: do it yourself.
> >
> >
> >
> >  On 5/12/08, Stut <stuttle@xxxxxxxxx> wrote:
> >  > On 12 May 2008, at 15:56, It flance wrote:
> >  >
> >  > > is there any function that can convert the result of  query to an
> >  > associative array?
> >  > >
> >  > > what i want is the following:
> >  > >
> >  > > $query = "select * from tablename";
> >  > > $result = mysql_query($query);
> >  > > $arr = somefunction($result);
> >  > >
> >  > > where $arr should be an assoiative array whose indices have the
> same name
> >  > as the fields names of table tablename.
> >  > >
> >  >
> >  >  http://php.net/mysql_fetch_assoc
> >  >
> >  >  Please please please read the manual: http://php.net/mysql
> >  >
> >  >  -Stut
> >  >
> >  >  --
> >  >  http://stut.net/
> >  >
> >  >
> >  >  --
> >  >  PHP General Mailing List (http://www.php.net/)
> >  >  To unsubscribe, visit: http://www.php.net/unsub.php
> >  >
> >  >
> >
> >
> >  --
> >  Regards,
> >  Wang Yi
> >
> >
> >
> >  --
> >  PHP General Mailing List (http://www.php.net/)
> >  To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
>
> --
>
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Regards,
Sanjeev
http://www.sanchanworld.com | http://webdirectory.sanchanworld.com - submit
your site

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux