Okay, hopefully this isn't too confusing. I'm doing a query on a product table and want to display only the items that are denoted as being a sale item. There are 5 categories that products can be grouped into. Two categories could have the same product depending if the item is unisex.
Getting the products that are sale items is the easy part. The part I'm having difficulty with is grouping and displaying the products like so:
Category 1
Product, Product, Product, etc.
Category 2
Product, Product, Product, etc.
Category 3
Product, Product, Product, etc.
Category 4
Product, Product, Product, etc.
Category 5
Product, Product, Product, etc.
I've come up with a few options, but want to get a second opinion or other options I might want to consider.
Option 1
Run 5 separate queries that match each category individually and display products from there.
Option 2
Run a single query and then run the results through a while loop and then do mysql_data_seek($result, 0); to reset the loop
$query = "SELECT products_id, products_category, products_gender, products_name, products_price, products_saleitem, products_saleprice, products_inventory, SUM(products_inventory) AS 'totalInv'
FROM products
WHERE products_saleitem = 'T' AND products_coid = '$myid' AND products_status = 'A'
GROUP BY products_name
ORDER BY products_category";
$result = mysql_query($query);
<?php
$i = 0;
while($row = mysql_fetch_array($result)) {
extract($row);
if ($i == 0) {
echo '<h4 class="category">CATEGORY 1</h4>';
}
if (($products_gender == 'U' || $products_gender == 'M') && ($products_category == 2 || $products_category == 1)) {
if ($i % 4 == 0 + 1) {
?>
<div class="thumb-one">
<a href="<?php htmlentities($_SERVER['PHP_SELF']);?>index.php?page=detail&productId=<?php echo $products_id; ?>&catId=<?php echo $products_category; ?>"><?php echo $products_name; ?></a>
</div>
<?
}
else {
?>
<div class ="thumb">
<a href="<?php htmlentities($_SERVER['PHP_SELF']);?>index.php?page=detail&productId=<?php echo $products_id; ?>&catId=<?php echo $products_category; ?>"><?php echo $products_name; ?></a>
</div>
<?
}
$i++;
}
}
mysql_data_seek($result, 0);
?>
Then repeat this code for Category 2, 3, 4 and 5. Am I on the right track with either of these?