Skip to main content
Inspiring
December 12, 2007
Question

Style, technique, and best practices question

  • December 12, 2007
  • 1 reply
  • 193 views
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
==================


This topic has been closed for replies.

1 reply

Inspiring
December 12, 2007
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