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

Style, technique, and best practices question

LEGEND ,
Dec 12, 2007 Dec 12, 2007
I have a database containing a number of products (say 1000). These
products are categorized into 5 different categories.

I want to deal with these products in ways that lead me to wonder the
following -

1. Is it better to have multiple recordsets (one for each category), or to
have a single recordset loaded into an array which can then be manipulated
on the page, e.g.,

$blah = array();
do {
$blah[] = $row_recordset;
} while ($row_recordset = mysql_fetch_assoc($rsrecordset));

2. Also, at present I have this method implemented like this -

<?php
$tester = array();
$socketTester = array();
$adapter = array();
$accessory = array();

do {
if (($row_rsTesters['ItemCatID']) == 4) { $tester[] = $row_rsTesters; }
if (($row_rsTesters['ItemCatID']) == 6) { $socketTester[] =
$row_rsTesters; }
if (($row_rsTesters['ItemCatID']) == 2) { $accessory[] = $row_rsTesters; }
if (($row_rsTesters['ItemCatID']) == 3) { $adapter[] = $row_rsTesters; }

} while ($row_rsTesters = mysql_fetch_assoc($rsTesters));

?>

Could I do it with a single array key, instead of multiple arrays?

<?php
$products = array();

do {
if (($row_rsTesters['ItemCatID']) == 4) { $products['tester'] =
$row_rsTesters; }
elseif (($row_rsTesters['ItemCatID']) == 6) { $products['socketTester'] =
$row_rsTesters; }
elseif (($row_rsTesters['ItemCatID']) == 2) { $products['accessory'] =
$row_rsTesters; }
elseif (($row_rsTesters['ItemCatID']) == 3) { $products['adapter'] =
$row_rsTesters; }

} while ($row_rsTesters = mysql_fetch_assoc($rsTesters));

--
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
==================


TOPICS
Server side applications
194
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 ,
Dec 12, 2007 Dec 12, 2007
LATEST
On Wed, 12 Dec 2007 10:15:55 -0500, "Murray *ACE*"
<forums@HAHAgreat-web-sights.com> wrote:

>I want to deal with these products in ways that lead me to wonder the
>following -
>
>1. Is it better to have multiple recordsets (one for each category), or to
>have a single recordset loaded into an array which can then be manipulated
>on the page, e.g.,

Manipulated? What is it you want to achieve? Generally, I'd say a single
query, resulting in a single recordset, would be more efficient than
several queries to the database, but how you'd do it would depend on
your goal.

Gary
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