Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Pls help with MySql syntax - i just want to query 1 category


marcus76

Recommended Posts

Posted

Hi,

 

I'd really appreciate it if someone could give me a pointer as to what i need to change in the following code:

 

I just want to specify a single category ID and return the products within this category - this code was taken from the rss.php file within the contribution here: http://www.oscommerce.com/community/contributions,1513

 

 

 

// Create SQL statement

$category = preg_replace('/[^0-9_]/', '', $_GET['cPath']);

$ecommerce = $_GET['ecommerce'];

if ($category != '') {

// Check to see if we are in a subcategory

if (strrpos($category, '_') > 0) {

$category = substr($category, strrpos($category, '_') + 1, strlen($category));

}

$catTable = ", products_to_categories pc ";

$catWhere = 'p.products_id = pc.products_id AND pc.categories_id = \'' . $category . '\' AND ';

}

 

$sql = "SELECT p.products_id, p.products_price, p.products_tax_class_id, p.products_model,

p.products_image, p.products_date_added, pd.products_name, pd.products_description,

m.manufacturers_name, cd.categories_name

FROM products p

$catTable

LEFT JOIN products_description pd

ON pd.products_id = p.products_id

AND pd.language_id = '$lang_id'

LEFT JOIN manufacturers m

ON m.manufacturers_id = p.manufacturers_id

LEFT JOIN products_to_categories p2c

ON p2c.products_id=p.products_id

LEFT JOIN categories_description cd

ON p2c.categories_id = cd.categories_id

AND cd.language_id = '$lang_id'

WHERE $catWhere

p.products_status=1 AND

p.products_to_rss=1

GROUP BY p.products_id

ORDER BY p.products_id DESC

LIMIT " . MAX_RSS_ARTICLES;

 

// Execute SQL query and get result

$sql_result = mysql_query($sql,$connection) or die("Couldn\'t execute query:<br />$sql");

Posted
I'd really appreciate it if someone could give me a pointer as to what i need to change in the following code:

 

Everything.

 

osCommerce uses PHP and MySQL. It doesn't use gobbledygook as a language.

 

Vger

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...