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

how to exclude a category from a product list

Engaged ,
Sep 26, 2012 Sep 26, 2012

I have all the products selected from the DB

$maxRows_Recordset1 = 56;

$pageNum_Recordset1 = 0;

if (isset($_GET['pageNum_Recordset1'])) {

  $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];

}

$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

mysql_select_db($database_beau, $beau);

$query_Recordset1 = "SELECT * FROM beauProd ORDER BY name ASC";

$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);

$Recordset1 = mysql_query($query_limit_Recordset1, $beau) or die(mysql_error());

$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($_GET['totalRows_Recordset1'])) {

  $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];

} else {

  $all_Recordset1 = mysql_query($query_Recordset1);

  $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);

}

$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;

but i have a category ID 21 that i dont want showing in with all the other products

what do i have to do

thanks in advance

TOPICS
Server side applications
1.2K
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

correct answers 1 Correct answer

LEGEND , Sep 27, 2012 Sep 27, 2012

Jon, this is just basic SQL.

If you wanted to include only rows from that category, you would do:

SELECT * FROM beauProd WHERE categoryID = 21 ORDER BY name ASC";

What do you think you need to change in the WHERE clause so that it excludes categoryID 21?

Translate
LEGEND ,
Sep 27, 2012 Sep 27, 2012

If category is a column in the beauProd table, then just exclude it in the WHERE clause.

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
Engaged ,
Sep 27, 2012 Sep 27, 2012

thought the where clause was to include not exclude?

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 ,
Sep 27, 2012 Sep 27, 2012

Of course not. You can combine conditions in the WHERE clause to filter IN or filter OUT any values you like.

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
Engaged ,
Sep 27, 2012 Sep 27, 2012

ok thank you. i will have a look on the net to see how to filter out.

thanks again

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 ,
Sep 27, 2012 Sep 27, 2012

Jon, this is just basic SQL.

If you wanted to include only rows from that category, you would do:

SELECT * FROM beauProd WHERE categoryID = 21 ORDER BY name ASC";

What do you think you need to change in the WHERE clause so that it excludes categoryID 21?

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
Engaged ,
Sep 28, 2012 Sep 28, 2012

SELECT * FROM beauProd WHERE categoryID ! = 21 ORDER BY name ASC";

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
Engaged ,
Sep 28, 2012 Sep 28, 2012

or

SELECT * FROM beauProd WHERE categoryID <> 21 ORDER BY name ASC";

i am going to try both of these

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
Engaged ,
Sep 28, 2012 Sep 28, 2012

SELECT * FROM beauProd WHERE categoryID ! = 21 ORDER BY name ASC";

worked

thanks for you help

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 ,
Sep 28, 2012 Sep 28, 2012

Good job.  The "!=" and "<>" are equivalent MySQL comparison operators, so both should work.

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
Engaged ,
Sep 28, 2012 Sep 28, 2012
LATEST

thanks for you help and point in the right direction. Bit of investigation and found it.

thanks again

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