Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
  • Sign Up

Авторекомендуемые товары с главной категории товара.


Recommended Posts

Здравствуйте.

 

помогите пожалуйста написать правильный sql запрос, чтоб показывались товары только с категории, выбранной в поле Главная категория, в карточке товара.

 

$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_category p2c LEFT JOIN " . DB_PREFIX . "product p ON (p2c.product_id = p.product_id) WHERE p2c.category_id IN (SELECT category_id FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "' AND p2c.main_category = '1')  AND p.product_id != '" . (int)$product_id . "' AND p.status = '1' ORDER BY RAND() LIMIT 0, 14");

 

 

 

Edited by magneto2010
Link to post
Share on other sites

SELECT p.* FROM " . DB_PREFIX . "product_to_category p2c 
LEFT JOIN " . DB_PREFIX . "product p ON (p2c.product_id = p.product_id) 
LEFT JOIN (SELECT p2c.category_id FROM " . DB_PREFIX . "product_to_category p2c 
			LEFT JOIN " . DB_PREFIX . "product p ON (p2c.product_id = p.product_id) 
			WHERE p2c.main_category = '1'
			AND product_id = '" . (int)$product_id . "' 
		) p2c2 ON p2c.category_id = p2c2.category_id
AND p.status = '1' 
ORDER BY RAND() LIMIT 0, 14;

Писал с листа не проверяя

  • +1 1
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.