Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

OT: PHP looping through an array

LEGEND ,
Oct 25, 2006 Oct 25, 2006
When I build a recordset, I create an array, right?

So, if I have this -

mysql_select_db($database_touchstone, $touchstone);
$query_rsCategory = "SELECT DISTINCT tclientsCategory FROM
tbl_orderedclients";
$rsCategory = mysql_query($query_rsCategory, $touchstone) or
die(mysql_error());
$row_rsCategory = mysql_fetch_assoc($rsCategory);
$totalRows_rsCategory = mysql_num_rows($rsCategory);

The variable called $row_rsCategory contains an array of all values in the
recordset, right?

So, why can't I get those values like this?

foreach ($row_rsCategory as $value) {
echo $value."<br>";
}


--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================



TOPICS
Server side applications
1.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 25, 2006 Oct 25, 2006
heheheheeh, I asked this a month ago. I am anxiously awaiting the answer...


"Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
news:ehnv6s$k1c$1@forums.macromedia.com...
> When I build a recordset, I create an array, right?
>
> So, if I have this -
>
> mysql_select_db($database_touchstone, $touchstone);
> $query_rsCategory = "SELECT DISTINCT tclientsCategory FROM
> tbl_orderedclients";
> $rsCategory = mysql_query($query_rsCategory, $touchstone) or
> die(mysql_error());
> $row_rsCategory = mysql_fetch_assoc($rsCategory);
> $totalRows_rsCategory = mysql_num_rows($rsCategory);
>
> The variable called $row_rsCategory contains an array of all values in the
> recordset, right?
>
> So, why can't I get those values like this?
>
> foreach ($row_rsCategory as $value) {
> echo $value."<br>";
> }
>
>
> --
> Murray --- ICQ 71997575
> Adobe Community Expert
> (If you *MUST* email me, don't LAUGH when you do so!)
> ==================
> http://www.dreamweavermx-templates.com - Template Triage!
> http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
> http://www.dwfaq.com - DW FAQs, Tutorials & Resources
> http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
> ==================
>
>
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 25, 2006 Oct 25, 2006
Murray *ACE* wrote:
> When I build a recordset, I create an array, right?

Wrong. You create a result resource.

> The variable called $row_rsCategory contains an array of all values in the
> recordset, right?

Wrong again. $row_rsCategory is an associative array containing a single
row.

> So, why can't I get those values like this?
>
> foreach ($row_rsCategory as $value) {
> echo $value."<br>";
> }

For the reasons stated above, all that will do is display the contents
of the first row.

You need to extract each row from your recordset with a loop in the same
way as a Dreamweaver repeat region does.

<?php
do {
foreach ($row_rsCategory as $value) {
echo $value."<br>";
}
} while($row_rsCategory = mysql_fetch_assoc($rsCategory));
?>


--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 25, 2006 Oct 25, 2006
Pass the dunce cap, will you? 8)

Thanks much, David.

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"David Powers" <david@example.com> wrote in message
news:eho0lk$lps$1@forums.macromedia.com...
> Murray *ACE* wrote:
>> When I build a recordset, I create an array, right?
>
> Wrong. You create a result resource.
>
>> The variable called $row_rsCategory contains an array of all values in
>> the recordset, right?
>
> Wrong again. $row_rsCategory is an associative array containing a single
> row.
>
>> So, why can't I get those values like this?
>>
>> foreach ($row_rsCategory as $value) {
>> echo $value."<br>";
>> }
>
> For the reasons stated above, all that will do is display the contents of
> the first row.
>
> You need to extract each row from your recordset with a loop in the same
> way as a Dreamweaver repeat region does.
>
> <?php
> do {
> foreach ($row_rsCategory as $value) {
> echo $value."<br>";
> }
> } while($row_rsCategory = mysql_fetch_assoc($rsCategory));
> ?>
>
>
> --
> David Powers
> Adobe Community Expert
> Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
> http://foundationphp.com/


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 25, 2006 Oct 25, 2006
Murray *ACE* wrote:
> Pass the dunce cap, will you? 8)

Here you are: <:(

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 25, 2006 Oct 25, 2006
David-

Can you think of a quick easy way to put this in an external function?

I was wanting to have a file which would take a recordset from a page, then
create an array (from a function), then spit back the array so that I could
work with one array within the page. Does that sound do-able or just overly
complicated?


> You need to extract each row from your recordset with a loop in the same
> way as a Dreamweaver repeat region does.
>
> <?php
> do {
> foreach ($row_rsCategory as $value) {
> echo $value."<br>";
> }
> } while($row_rsCategory = mysql_fetch_assoc($rsCategory));
> ?>
>
>
> --
> David Powers
> Adobe Community Expert
> Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
> http://foundationphp.com/


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 25, 2006 Oct 25, 2006
Multi-dimensional even -

do {
foreach ($row_rsCategory as $value) {
$categories[][0] = $value;
}
} while($row_rsCategory = mysql_fetch_assoc($rsCategory));


--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"crash" <crash@bcdcdigital.com> wrote in message
news:eho3mc$pgi$1@forums.macromedia.com...
> David-
>
> Can you think of a quick easy way to put this in an external function?
>
> I was wanting to have a file which would take a recordset from a page,
> then create an array (from a function), then spit back the array so that I
> could work with one array within the page. Does that sound do-able or
> just overly complicated?
>
>
>> You need to extract each row from your recordset with a loop in the same
>> way as a Dreamweaver repeat region does.
>>
>> <?php
>> do {
>> foreach ($row_rsCategory as $value) {
>> echo $value."<br>";
>> }
>> } while($row_rsCategory = mysql_fetch_assoc($rsCategory));
>> ?>
>>
>>
>> --
>> David Powers
>> Adobe Community Expert
>> Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
>> http://foundationphp.com/
>
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 25, 2006 Oct 25, 2006
I tried that, can't pass it to a function outside of the page? Unless I
made a mistake I'm not catching - I made these files almost a month ago, I
think.

What I have is this:

inside my page
do/while that feeds my data to outside functions, which then populate the
html inside the do/while loop.

do
set data up through outside functions
while

What I would much rather do is have a single function on my page, so

create_listing($recordset);

but I don't seem to be able to pull a "recordset block" out of the page and
into my functions.

Does that make sense?

Jon
"Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
news:eho3rp$pq5$1@forums.macromedia.com...
> Multi-dimensional even -
>
> do {
> foreach ($row_rsCategory as $value) {
> $categories[][0] = $value;
> }
> } while($row_rsCategory = mysql_fetch_assoc($rsCategory));
>
>
> --
> Murray --- ICQ 71997575
> Adobe Community Expert
> (If you *MUST* email me, don't LAUGH when you do so!)
> ==================
> http://www.dreamweavermx-templates.com - Template Triage!
> http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
> http://www.dwfaq.com - DW FAQs, Tutorials & Resources
> http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
> ==================
>
>
> "crash" <crash@bcdcdigital.com> wrote in message
> news:eho3mc$pgi$1@forums.macromedia.com...
>> David-
>>
>> Can you think of a quick easy way to put this in an external function?
>>
>> I was wanting to have a file which would take a recordset from a page,
>> then create an array (from a function), then spit back the array so that
>> I could work with one array within the page. Does that sound do-able or
>> just overly complicated?
>>
>>
>>> You need to extract each row from your recordset with a loop in the same
>>> way as a Dreamweaver repeat region does.
>>>
>>> <?php
>>> do {
>>> foreach ($row_rsCategory as $value) {
>>> echo $value."<br>";
>>> }
>>> } while($row_rsCategory = mysql_fetch_assoc($rsCategory));
>>> ?>
>>>
>>>
>>> --
>>> David Powers
>>> Adobe Community Expert
>>> Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
>>> http://foundationphp.com/
>>
>>
>
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 25, 2006 Oct 25, 2006
In the code I gave you, $categories[$i][0] would contain all of the
recordset's values for each value of $i up to the number of records, no?
Why can't you manipulate that?

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"crash" <crash@bcdcdigital.com> wrote in message
news:eho4s6$r1d$1@forums.macromedia.com...
>I tried that, can't pass it to a function outside of the page? Unless I
>made a mistake I'm not catching - I made these files almost a month ago, I
>think.
>
> What I have is this:
>
> inside my page
> do/while that feeds my data to outside functions, which then populate the
> html inside the do/while loop.
>
> do
> set data up through outside functions
> while
>
> What I would much rather do is have a single function on my page, so
>
> create_listing($recordset);
>
> but I don't seem to be able to pull a "recordset block" out of the page
> and into my functions.
>
> Does that make sense?
>
> Jon
> "Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
> news:eho3rp$pq5$1@forums.macromedia.com...
>> Multi-dimensional even -
>>
>> do {
>> foreach ($row_rsCategory as $value) {
>> $categories[][0] = $value;
>> }
>> } while($row_rsCategory = mysql_fetch_assoc($rsCategory));
>>
>>
>> --
>> Murray --- ICQ 71997575
>> Adobe Community Expert
>> (If you *MUST* email me, don't LAUGH when you do so!)
>> ==================
>> http://www.dreamweavermx-templates.com - Template Triage!
>> http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
>> http://www.dwfaq.com - DW FAQs, Tutorials & Resources
>> http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
>> ==================
>>
>>
>> "crash" <crash@bcdcdigital.com> wrote in message
>> news:eho3mc$pgi$1@forums.macromedia.com...
>>> David-
>>>
>>> Can you think of a quick easy way to put this in an external function?
>>>
>>> I was wanting to have a file which would take a recordset from a page,
>>> then create an array (from a function), then spit back the array so that
>>> I could work with one array within the page. Does that sound do-able or
>>> just overly complicated?
>>>
>>>
>>>> You need to extract each row from your recordset with a loop in the
>>>> same way as a Dreamweaver repeat region does.
>>>>
>>>> <?php
>>>> do {
>>>> foreach ($row_rsCategory as $value) {
>>>> echo $value."<br>";
>>>> }
>>>> } while($row_rsCategory = mysql_fetch_assoc($rsCategory));
>>>> ?>
>>>>
>>>>
>>>> --
>>>> David Powers
>>>> Adobe Community Expert
>>>> Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
>>>> http://foundationphp.com/
>>>
>>>
>>
>>
>
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 25, 2006 Oct 25, 2006
.oO(crash)

>Can you think of a quick easy way to put this in an external function?
>
>I was wanting to have a file which would take a recordset from a page, then
>create an array (from a function), then spit back the array so that I could
>work with one array within the page. Does that sound do-able or just overly
>complicated?

Something like this?

<?php
function mysqlFetchAll($rs, $resultType = MYSQL_BOTH) {
$result = array();
while ($record = mysql_fetch_array($rs, $resultType)) {
$result[] = $record;
}
return $result;
}
?>

Allowed values for the optional $resultType parameter are MYSQL_ASSOC,
MYSQL_NUM and MYSQL_BOTH.

http://www.php.net/manual/en/function.mysql-fetch-array.php

JFTR: The PDO extension already has such a function, but PDO is not
available on all servers.

http://www.php.net/manual/en/function.pdostatement-fetchall.php

Micha
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 25, 2006 Oct 25, 2006
Nice. I like that, and have stolen it for my own personal exploitation.
Muhahahhahaha!

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"Michael Fesser" <netizen@gmx.de> wrote in message
news:0a7vj2l3h6npmtadu9rjkp5g4slrqnt439@4ax.com...
> .oO(crash)
>
>>Can you think of a quick easy way to put this in an external function?
>>
>>I was wanting to have a file which would take a recordset from a page,
>>then
>>create an array (from a function), then spit back the array so that I
>>could
>>work with one array within the page. Does that sound do-able or just
>>overly
>>complicated?
>
> Something like this?
>
> <?php
> function mysqlFetchAll($rs, $resultType = MYSQL_BOTH) {
> $result = array();
> while ($record = mysql_fetch_array($rs, $resultType)) {
> $result[] = $record;
> }
> return $result;
> }
> ?>
>
> Allowed values for the optional $resultType parameter are MYSQL_ASSOC,
> MYSQL_NUM and MYSQL_BOTH.
>
> http://www.php.net/manual/en/function.mysql-fetch-array.php
>
> JFTR: The PDO extension already has such a function, but PDO is not
> available on all servers.
>
> http://www.php.net/manual/en/function.pdostatement-fetchall.php
>
> Micha


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 25, 2006 Oct 25, 2006
b/c the do-while was nested inside your original document.

I need a means to pass an object to a function, so I can re-use the
recordset, w/o knowing which recordset it is.

I'll take another look, Murray, after I get back from lunch. I'm starving
and distracted by it. it's possible your code will work - just let me take
another look at it.

Thanks for having a go!

Jon
"Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
news:eho5ot$s7p$1@forums.macromedia.com...
> In the code I gave you, $categories[$i][0] would contain all of the
> recordset's values for each value of $i up to the number of records, no?
> Why can't you manipulate that?
>
> --
> Murray --- ICQ 71997575
> Adobe Community Expert
> (If you *MUST* email me, don't LAUGH when you do so!)
> ==================
> http://www.dreamweavermx-templates.com - Template Triage!
> http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
> http://www.dwfaq.com - DW FAQs, Tutorials & Resources
> http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
> ==================
>
>
> "crash" <crash@bcdcdigital.com> wrote in message
> news:eho4s6$r1d$1@forums.macromedia.com...
>>I tried that, can't pass it to a function outside of the page? Unless I
>>made a mistake I'm not catching - I made these files almost a month ago, I
>>think.
>>
>> What I have is this:
>>
>> inside my page
>> do/while that feeds my data to outside functions, which then populate the
>> html inside the do/while loop.
>>
>> do
>> set data up through outside functions
>> while
>>
>> What I would much rather do is have a single function on my page, so
>>
>> create_listing($recordset);
>>
>> but I don't seem to be able to pull a "recordset block" out of the page
>> and into my functions.
>>
>> Does that make sense?
>>
>> Jon
>> "Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
>> news:eho3rp$pq5$1@forums.macromedia.com...
>>> Multi-dimensional even -
>>>
>>> do {
>>> foreach ($row_rsCategory as $value) {
>>> $categories[][0] = $value;
>>> }
>>> } while($row_rsCategory = mysql_fetch_assoc($rsCategory));
>>>
>>>
>>> --
>>> Murray --- ICQ 71997575
>>> Adobe Community Expert
>>> (If you *MUST* email me, don't LAUGH when you do so!)
>>> ==================
>>> http://www.dreamweavermx-templates.com - Template Triage!
>>> http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
>>> http://www.dwfaq.com - DW FAQs, Tutorials & Resources
>>> http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
>>> ==================
>>>
>>>
>>> "crash" <crash@bcdcdigital.com> wrote in message
>>> news:eho3mc$pgi$1@forums.macromedia.com...
>>>> David-
>>>>
>>>> Can you think of a quick easy way to put this in an external function?
>>>>
>>>> I was wanting to have a file which would take a recordset from a page,
>>>> then create an array (from a function), then spit back the array so
>>>> that I could work with one array within the page. Does that sound
>>>> do-able or just overly complicated?
>>>>
>>>>
>>>>> You need to extract each row from your recordset with a loop in the
>>>>> same way as a Dreamweaver repeat region does.
>>>>>
>>>>> <?php
>>>>> do {
>>>>> foreach ($row_rsCategory as $value) {
>>>>> echo $value."<br>";
>>>>> }
>>>>> } while($row_rsCategory = mysql_fetch_assoc($rsCategory));
>>>>> ?>
>>>>>
>>>>>
>>>>> --
>>>>> David Powers
>>>>> Adobe Community Expert
>>>>> Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
>>>>> http://foundationphp.com/
>>>>
>>>>
>>>
>>>
>>
>>
>
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 25, 2006 Oct 25, 2006
YES YES YES YES

that's *exactly* what I was looking for, I believe. I did not know the
proper syntax, I guess. I was using mysql_fetch to try to change -ah who
cares what i was doing!! hehehe - thanks mate, I can't wait to get back from
lunch and have another peek at my stuff!

Thanks agian, Micha!

Jon

"Michael Fesser" <netizen@gmx.de> wrote in message
news:0a7vj2l3h6npmtadu9rjkp5g4slrqnt439@4ax.com...
> .oO(crash)
>
>>Can you think of a quick easy way to put this in an external function?
>>
>>I was wanting to have a file which would take a recordset from a page,
>>then
>>create an array (from a function), then spit back the array so that I
>>could
>>work with one array within the page. Does that sound do-able or just
>>overly
>>complicated?
>
> Something like this?
>
> <?php
> function mysqlFetchAll($rs, $resultType = MYSQL_BOTH) {
> $result = array();
> while ($record = mysql_fetch_array($rs, $resultType)) {
> $result[] = $record;
> }
> return $result;
> }
> ?>
>
> Allowed values for the optional $resultType parameter are MYSQL_ASSOC,
> MYSQL_NUM and MYSQL_BOTH.
>
> http://www.php.net/manual/en/function.mysql-fetch-array.php
>
> JFTR: The PDO extension already has such a function, but PDO is not
> available on all servers.
>
> http://www.php.net/manual/en/function.pdostatement-fetchall.php
>
> Micha


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 25, 2006 Oct 25, 2006
.oO(Murray *ACE*)

>Nice. I like that, and have stolen it for my own personal exploitation.
>Muhahahhahaha!

Thanks for buying online. Please send your money to my PayPal account.
;)

Now for part 2:

<?php
function createListing($rs) {
$result = '';
$data = mysqlFetchAll($rs, MYSQL_ASSOC);
if (!empty($data)) {
$result .= "<ul>\n";
foreach ($data as $record) {
$result .= '<li>';
$result .= $record['foo']; // output record data here
$result .= "</li>\n";
}
$result .= "</ul>\n";
}
return $result;
}
?>

Or something like that.

Micha
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 25, 2006 Oct 25, 2006
LMFAO--Micha's looks a little simpiler than mine. ;o)


"Michael Fesser" <netizen@gmx.de> wrote in message
news:s18vj2h82qhi6041ab591bv21bbe5kpeir@4ax.com...
> .oO(Murray *ACE*)
>
>>Nice. I like that, and have stolen it for my own personal exploitation.
>>Muhahahhahaha!
>
> Thanks for buying online. Please send your money to my PayPal account.
> ;)
>
> Now for part 2:
>
> <?php
> function createListing($rs) {
> $result = '';
> $data = mysqlFetchAll($rs, MYSQL_ASSOC);
> if (!empty($data)) {
> $result .= "<ul>\n";
> foreach ($data as $record) {
> $result .= '<li>';
> $result .= $record['foo']; // output record data here
> $result .= "</li>\n";
> }
> $result .= "</ul>\n";
> }
> return $result;
> }
> ?>
>
> Or something like that.
>
> Micha


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 25, 2006 Oct 25, 2006
Micha:

Why not use the mysql_fetch_array() function for this?

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"Michael Fesser" <netizen@gmx.de> wrote in message
news:s18vj2h82qhi6041ab591bv21bbe5kpeir@4ax.com...
> .oO(Murray *ACE*)
>
>>Nice. I like that, and have stolen it for my own personal exploitation.
>>Muhahahhahaha!
>
> Thanks for buying online. Please send your money to my PayPal account.
> ;)
>
> Now for part 2:
>
> <?php
> function createListing($rs) {
> $result = '';
> $data = mysqlFetchAll($rs, MYSQL_ASSOC);
> if (!empty($data)) {
> $result .= "<ul>\n";
> foreach ($data as $record) {
> $result .= '<li>';
> $result .= $record['foo']; // output record data here
> $result .= "</li>\n";
> }
> $result .= "</ul>\n";
> }
> return $result;
> }
> ?>
>
> Or something like that.
>
> Micha


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 25, 2006 Oct 25, 2006
.oO(Murray *ACE*)

>Why not use the mysql_fetch_array() function for this?

I was just using my function from the previous post to get all data from
a recordset into an array first. mysql_fetch_array() just returns a
single row, not the entire result set.

Micha
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 25, 2006 Oct 25, 2006
Right - but I meant replace the business end of the while statement with the
fetch_array() function?

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"Michael Fesser" <netizen@gmx.de> wrote in message
news:259vj2da8ar2ha36keju1pv7fg82vs7pto@4ax.com...
> .oO(Murray *ACE*)
>
>>Why not use the mysql_fetch_array() function for this?
>
> I was just using my function from the previous post to get all data from
> a recordset into an array first. mysql_fetch_array() just returns a
> single row, not the entire result set.
>
> Micha


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 25, 2006 Oct 25, 2006
.oO(Murray *ACE*)

>Right - but I meant replace the business end of the while statement with the
>fetch_array() function?

Hmm? Not sure what you mean.

Micha
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 25, 2006 Oct 25, 2006
Neither am I.

I now understand that the fetch array function only gets a single row from
the table into that array.

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"Michael Fesser" <netizen@gmx.de> wrote in message
news:23evj29ejpg9d6hdco00pm756octphqsnu@4ax.com...
> .oO(Murray *ACE*)
>
>>Right - but I meant replace the business end of the while statement with
>>the
>>fetch_array() function?
>
> Hmm? Not sure what you mean.
>
> Micha


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 25, 2006 Oct 25, 2006
but you can use seek to get the next one, yes? is that what you were
thinking of?

"Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
news:ehof3c$aeb$1@forums.macromedia.com...
> Neither am I.
>
> I now understand that the fetch array function only gets a single row from
> the table into that array.
>
> --
> Murray --- ICQ 71997575
> Adobe Community Expert
> (If you *MUST* email me, don't LAUGH when you do so!)
> ==================
> http://www.dreamweavermx-templates.com - Template Triage!
> http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
> http://www.dwfaq.com - DW FAQs, Tutorials & Resources
> http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
> ==================
>
>
> "Michael Fesser" <netizen@gmx.de> wrote in message
> news:23evj29ejpg9d6hdco00pm756octphqsnu@4ax.com...
>> .oO(Murray *ACE*)
>>
>>>Right - but I meant replace the business end of the while statement with
>>>the
>>>fetch_array() function?
>>
>> Hmm? Not sure what you mean.
>>
>> Micha
>
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 25, 2006 Oct 25, 2006
Who, me?

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"crash" <crash@bcdcdigital.com> wrote in message
news:ehofb5$amv$1@forums.macromedia.com...
> but you can use seek to get the next one, yes? is that what you were
> thinking of?
>
> "Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
> news:ehof3c$aeb$1@forums.macromedia.com...
>> Neither am I.
>>
>> I now understand that the fetch array function only gets a single row
>> from the table into that array.
>>
>> --
>> Murray --- ICQ 71997575
>> Adobe Community Expert
>> (If you *MUST* email me, don't LAUGH when you do so!)
>> ==================
>> http://www.dreamweavermx-templates.com - Template Triage!
>> http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
>> http://www.dwfaq.com - DW FAQs, Tutorials & Resources
>> http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
>> ==================
>>
>>
>> "Michael Fesser" <netizen@gmx.de> wrote in message
>> news:23evj29ejpg9d6hdco00pm756octphqsnu@4ax.com...
>>> .oO(Murray *ACE*)
>>>
>>>>Right - but I meant replace the business end of the while statement with
>>>>the
>>>>fetch_array() function?
>>>
>>> Hmm? Not sure what you mean.
>>>
>>> Micha
>>
>>
>
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 25, 2006 Oct 25, 2006
yeah, nevermind, iv'e got too many irons in the far.

jon

"Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
news:ehog5g$bpr$1@forums.macromedia.com...
> Who, me?
>
> --
> Murray --- ICQ 71997575
> Adobe Community Expert
> (If you *MUST* email me, don't LAUGH when you do so!)
> ==================
> http://www.dreamweavermx-templates.com - Template Triage!
> http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
> http://www.dwfaq.com - DW FAQs, Tutorials & Resources
> http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
> ==================
>
>
> "crash" <crash@bcdcdigital.com> wrote in message
> news:ehofb5$amv$1@forums.macromedia.com...
>> but you can use seek to get the next one, yes? is that what you were
>> thinking of?
>>
>> "Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
>> news:ehof3c$aeb$1@forums.macromedia.com...
>>> Neither am I.
>>>
>>> I now understand that the fetch array function only gets a single row
>>> from the table into that array.
>>>
>>> --
>>> Murray --- ICQ 71997575
>>> Adobe Community Expert
>>> (If you *MUST* email me, don't LAUGH when you do so!)
>>> ==================
>>> http://www.dreamweavermx-templates.com - Template Triage!
>>> http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
>>> http://www.dwfaq.com - DW FAQs, Tutorials & Resources
>>> http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
>>> ==================
>>>
>>>
>>> "Michael Fesser" <netizen@gmx.de> wrote in message
>>> news:23evj29ejpg9d6hdco00pm756octphqsnu@4ax.com...
>>>> .oO(Murray *ACE*)
>>>>
>>>>>Right - but I meant replace the business end of the while statement
>>>>>with the
>>>>>fetch_array() function?
>>>>
>>>> Hmm? Not sure what you mean.
>>>>
>>>> Micha
>>>
>>>
>>
>>
>
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 26, 2006 Oct 26, 2006
Its completely doable, I created a custom database class years back, which
does this. I use it in every project and it makes it so much easier to work
with the database, and has saved me untold amount of time. To read a
recordset you just use

$db = new Database();
$sql = "SELECT * FROM table";
$db->dbOpenDatabase();
$results = $db->dbResults($sql);
$db->dbCloseDatabase();

$results is then an array of record arrays, and you can loop through it
easily with foreach()

The dbResults function is:

function dbResults($query){
// Execute an SQL query and return results in an Array
$dbResult = mysql_query($query, $this->dbLink)
or die ("Database: MySQL Error: " . mysql_error() );
$numRecords = mysql_num_rows($dbResult);
$dataArray = "";
for($i=0;$i<$numRecords;$i++){
$row = mysql_fetch_assoc($dbResult);
$dataArray[] = $row;
}
return $dataArray;
}

Obviously you`d need to change the parameters to put in the link to the
database etc

Its well worth making a custom database class, as it can become invaluable
and saves coding the same things over and over. I have the basic functions
in one class:

dbOpenDatabase()
dbResults()
dbNumRecords()
dbAddRecord()
dbDeleteRecord()
dbUpdateRecord()
dbCloseDatabase()

dbAddRecord,dbDeleteRecord,dbUpdateRecord all do the same thing, ie running
the passed sql but it makes the code easier to read.

Any extra functions you need for projects can be put in another class that
extends the basic database class.

Gareth
http://www.phploginsuite.co.uk/
PHP Login Suite V2 - 34 Server Behaviors to build a complete Login system.


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 26, 2006 Oct 26, 2006
Gareth,

Is this the class you wrote about for DMX Zone ?

--

Dave Buchholz
I-CRE8
www.i-cre8.co.uk
Skype ID: I-CRE8


"gareth" <gareth@buzzinet.co.uk> wrote in message
news:ehq0kq$700$1@forums.macromedia.com...
Its completely doable, I created a custom database class years back, which
does this. I use it in every project and it makes it so much easier to work
with the database, and has saved me untold amount of time. To read a
recordset you just use

$db = new Database();
$sql = "SELECT * FROM table";
$db->dbOpenDatabase();
$results = $db->dbResults($sql);
$db->dbCloseDatabase();

$results is then an array of record arrays, and you can loop through it
easily with foreach()

The dbResults function is:

function dbResults($query){
// Execute an SQL query and return results in an Array
$dbResult = mysql_query($query, $this->dbLink)
or die ("Database: MySQL Error: " . mysql_error() );
$numRecords = mysql_num_rows($dbResult);
$dataArray = "";
for($i=0;$i<$numRecords;$i++){
$row = mysql_fetch_assoc($dbResult);
$dataArray[] = $row;
}
return $dataArray;
}

Obviously you`d need to change the parameters to put in the link to the
database etc

Its well worth making a custom database class, as it can become invaluable
and saves coding the same things over and over. I have the basic functions
in one class:

dbOpenDatabase()
dbResults()
dbNumRecords()
dbAddRecord()
dbDeleteRecord()
dbUpdateRecord()
dbCloseDatabase()

dbAddRecord,dbDeleteRecord,dbUpdateRecord all do the same thing, ie running
the passed sql but it makes the code easier to read.

Any extra functions you need for projects can be put in another class that
extends the basic database class.

Gareth
http://www.phploginsuite.co.uk/
PHP Login Suite V2 - 34 Server Behaviors to build a complete Login system.



Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines