Jump to content
Sign in to follow this  
koreshok

[Решено] Undefined index: category_id in ...

Recommended Posts

вывожу в товаре похожие продукты, но.. если товар не привязан к категории появляется

<b>Notice</b>: Undefined index: category_id in

ругается на строку  

$category = $this->db->query("SELECT category_id FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" .$product_id. "'");
$category_id = $category->row['category_id'];

подскажите, как поправить

Edited by koreshok

Share this post


Link to post
Share on other sites

if (isset($category->row['category_id']))

$category_id = $category->row['category_id'];

 

или

 

if ($category)

$category_id = $category->row['category_id'];

 

или

 

if ($category->num_rows>0)

$category_id = $category->row['category_id'];

 

 

типа того, в зависимости от того, откуда берется $category

Edited by nikifalex

Share this post


Link to post
Share on other sites

не помогло....

если отключить показ ошибок, то все ровно и красиво, тем более , что это единичный товар... но хотелось бы исправить

Edited by koreshok

Share this post


Link to post
Share on other sites

не может быть

может... могу тимвиер включить...сами попробуйте

Share this post


Link to post
Share on other sites

на хостинге без проблем разберусь.

через tv морально не готов, сорри.

Share this post


Link to post
Share on other sites
$category = $this->db->query("SELECT category_id FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" .$product_id. "'");

if (isset($category->row['category_id'])) {

$category_id = $category->row['category_id'];

} else {

$category_id = привязать к какой-то категории (id), раз не указано

}

Share this post


Link to post
Share on other sites

спасибо, вопрос закрыт

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×

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.