Skip to main content
Inspiring
November 4, 2007
Question

Recordset into an array?

  • November 4, 2007
  • 9 replies
  • 2080 views
What function would I use to load an entire recordset into an array?

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


This topic has been closed for replies.

9 replies

Inspiring
November 4, 2007
Thanks for your persistance in drilling this stuff through my noggin, David.

Luckily, I had commented out that part of the DW markup! 8)

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


"David Powers" <david@example.com> wrote in message
news:fgl2jv$cu8$1@forums.macromedia.com...
> Murray *ACE* wrote:
>> Yeah - I wound up doing this -
>>
>> while($row = mysql_fetch_assoc($rsRates)){
>> $array[] = $row; }
>
> As I explained before, because of the way that Dreamweaver creates a
> recordset, you need to use a do... while loop. If you don't, and you place
> the preceding code after the recordset code, the first record will be
> missing.
>
> This is because the code generated by Dreamweaver automatically retrieves
> the first record in this line:
>
> $row_recordsetName = mysql_fetch_assoc($recordsetName);
>
> --
> David Powers, Adobe Community Expert
> Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
> Author, "PHP Solutions" (friends of ED)
> http://foundationphp.com/

Inspiring
November 4, 2007
Murray *ACE* wrote:
> Yeah - I wound up doing this -
>
> while($row = mysql_fetch_assoc($rsRates)){
> $array[] = $row; }

As I explained before, because of the way that Dreamweaver creates a
recordset, you need to use a do... while loop. If you don't, and you
place the preceding code after the recordset code, the first record will
be missing.

This is because the code generated by Dreamweaver automatically
retrieves the first record in this line:

$row_recordsetName = mysql_fetch_assoc($recordsetName);

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Inspiring
May 2, 2011

When i tried this, the only result I got was the word Array.  I am trying to get the results of my RS and pass them into Excel.  I've got everything working except for the ability to get all records.  It only gives me the first record, and when I use while loop, it only gives me the second.  Do While loops doesn't return anything.

Inspiring
November 4, 2007
Yeah - I wound up doing this -

while($row = mysql_fetch_assoc($rsRates)){
$array[] = $row; }

> If you want to use the recordset (as opposed to the array just created)
> later in the same page, you need to reset the result resource like this:
>
> mysql_data_seek($recordsetName, 0);

Thank you for anticipating a question. That's excellent!

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


"David Powers" <david@example.com> wrote in message
news:fgkpaq$28r$1@forums.macromedia.com...
> Joris van Lier wrote:
>> in PHP Mysql it's already an array isn't it?
>
> No, it's not. It's a resource, which is a completely different data type.
>
> To put the whole recordset in an array, you need to loop through it.
> Because of the way Dreamweaver codes a recordset, it requires a do...
> while loop.
>
> $myArray = array();
> do {
> $myArray[] = $row_recordsetName;
> } while ($row_recordsetName = mysql_fetch_assoc($recordsetName));
>
> If you want to use the recordset (as opposed to the array just created)
> later in the same page, you need to reset the result resource like this:
>
> mysql_data_seek($recordsetName, 0);
>
> --
> David Powers, Adobe Community Expert
> Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
> Author, "PHP Solutions" (friends of ED)
> http://foundationphp.com/

Inspiring
November 4, 2007
Joris van Lier wrote:
> in PHP Mysql it's already an array isn't it?

No, it's not. It's a resource, which is a completely different data type.

To put the whole recordset in an array, you need to loop through it.
Because of the way Dreamweaver codes a recordset, it requires a do...
while loop.

$myArray = array();
do {
$myArray[] = $row_recordsetName;
} while ($row_recordsetName = mysql_fetch_assoc($recordsetName));

If you want to use the recordset (as opposed to the array just created)
later in the same page, you need to reset the result resource like this:

mysql_data_seek($recordsetName, 0);

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Inspiring
November 4, 2007
LAMP....

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


"Joris van Lier" <whizzrd@hotmail.com> wrote in message
news:fgkjkp$olq$1@forums.macromedia.com...
> "Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
> news:fgki3r$mt8$1@forums.macromedia.com...
>> Yes. Oops....
>
> .. so what is it....Coldfusion, JSP, .NET ? :)

Inspiring
November 4, 2007
"Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
news:fgki3r$mt8$1@forums.macromedia.com...
> Yes. Oops....

.. so what is it....Coldfusion, JSP, .NET ? :)

Inspiring
November 4, 2007
Yes. Oops....

Thanks for the gentle reminder!

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


"Joris van Lier" <whizzrd@hotmail.com> wrote in message
news:fgkh1u$ljn$1@forums.macromedia.com...
> "Joris van Lier" <whizzrd@hotmail.com> wrote in message
> news:fgkgsh$lbf$1@forums.macromedia.com...
>> in PHP Mysql it's already an array isn't it?
>
> http://www.weberdev.com/get_example-4065.html
>
>

Inspiring
November 4, 2007
"Joris van Lier" <whizzrd@hotmail.com> wrote in message
news:fgkgsh$lbf$1@forums.macromedia.com...
> in PHP Mysql it's already an array isn't it?

http://www.weberdev.com/get_example-4065.html


Inspiring
November 4, 2007
"Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
news:fgkgj3$kvh$1@forums.macromedia.com...
> What function would I use to load an entire recordset into an array?

Aww c'mon Murray, you know better than not to state what servermodel you
need..

Asp: Recordset1.GetRows() http://www.w3schools.com/ado/met_rs_getrows.asp
Phakt: $recordset->GetRows($nrows)
in PHP Mysql it's already an array isn't it?

Joris