Skip to main content
Inspiring
April 12, 2013
Answered

filter recordset category to sub category not working, what am i doing wrong

  • April 12, 2013
  • 18 replies
  • 3763 views

I have done this lots of times but must have made a mistake because i cant get it to work

i have a category list displaying all categories

ymysql_select_db($database_lotties, $lotties);

$query_rsProductData = "SELECT * FROM lottieCat ORDER BY lottieCat.CatName";

$rsProductData = mysql_query($query_rsProductData, $lotties) or die(mysql_error());

$row_rsProductData = mysql_fetch_assoc($rsProductData);

$totalRows_rsProductData = mysql_num_rows($rsProductData);

?>

        <?php do { ?>

          <a href="subCat-list.php?subCat=<?php echo $row_rsProductData['subCatID']; ?>"><?php echo $row_rsProductData['CatName']; ?><br />

</a>

          <?php } while ($row_rsProductData = mysql_fetch_assoc($rsProductData)); ?>

<?php

mysql_free_result($rsProductData);

?>

but on the link i want to send the to the sub category page but it isnt working. below is the sql for the sub category page

$varCat_rsProductData = "0";

if (isset($_GET["subCat"])) {

  $varCat_rsProductData = $_GET["subCat"];

}

mysql_select_db($database_lotties, $lotties);

$query_rsProductData = sprintf("SELECT * FROM LOTTIE_subCats, lottieCat WHERE lottieCat.CatID = LOTTIE_subCats.CatID AND lottieCat.CatID = %s", GetSQLValueString($varCat_rsProductData, "int"));

$query_limit_rsProductData = sprintf("%s LIMIT %d, %d", $query_rsProductData, $startRow_rsProductData, $maxRows_rsProductData);

$rsProductData = mysql_query($query_limit_rsProductData, $lotties) or die(mysql_error());

$row_rsProductData = mysql_fetch_assoc($rsProductData);

the joins in the table are

table = lottieCat

CatID

Catname

table=LOTTIE_subCats

subCatID

CatID

then the products is

table = LOTTIE_products

subCatID

what am i doing wrong

This topic has been closed for replies.
Correct answer bregent

I have included content now, will this help?

lottieCat

CatID

1

2

3

4

CatName

tools

cutters

bags

equiptment

CatImage

image1.jpg

image2.jpg

image3.jpg

image4.jpg

-----------------------------------

LOTTIE_subCats

subCatID

1

2

3

CatID

1

1

2

subCatName

Plastic Tools

Metal Tools

Plunger Cutters

subCatImage

cat-dec-tools1365679004.JPG

metal1365679023.jpg

flower plunger1366019771.jpg


thanks


OK, so if you want to produce a list of subcategories, you don't need to join to the category table.

$query_rsProductData = "SELECT * LOTTIE_subCats WHERE LOTTIE_subCats.CatID = %s ;

18 replies

Inspiring
April 12, 2013

ok i think i need to add some more to the statement of the category list so i changed this to

mysql_select_db($database_lotties, $lotties);

$query_rsProductData = "SELECT * FROM lottieCat, LOTTIE_subCats WHERE LOTTIE_subCats.subCatID = lottieCat.CatID  ORDER BY lottieCat.CatName";

$rsProductData = mysql_query($query_rsProductData, $lotties) or die(mysql_error());

$row_rsProductData = mysql_fetch_assoc($rsProductData);

$totalRows_rsProductData = mysql_num_rows($rsProductData);

this then gives me a sub category value the values are of the categories and not the sub categories

Inspiring
April 12, 2013

ok i have now done the following

mysql_select_db($database_lotties, $lotties);

$query_rsProductData = "SELECT * FROM lottieCat, LOTTIE_subCats WHERE LOTTIE_subCats.CatID = lottieCat.CatID  ORDER BY lottieCat.CatName";

$rsProductData = mysql_query($query_rsProductData, $lotties) or die(mysql_error());

$row_rsProductData = mysql_fetch_assoc($rsProductData);

$totalRows_rsProductData = mysql_num_rows($rsProductData);

it is showing now in the list the correct subcategories BUT if the are two products in that sub category (example Tools a red one and a blue one) it is showing tools twice

Participating Frequently
April 12, 2013

>$query_rsProductData = "SELECT * FROM lottieCat, LOTTIE_subCats

>WHERE LOTTIE_subCats.CatID = lottieCat.CatID  ORDER BY lottieCat.CatName";

That query doesn't even have a filter. Not sure what you are trying to do here.

>it is showing now in the list the correct subcategories BUT

>if the are two products in that sub category (example Tools

>a red one and a blue one) it is showing tools twice

Then you have a problem with your data, because you are not even including the product table in that query.