Jump to content
  • разработка интернет магазинов на opencart
  • доработка интернет магазинов на opencart

помогите с запросом, ступор


Recommended Posts

Хочу добавить в model/category  функцию вывода category_id по названию.

public function getIdCategory($category_name) {
$query="SELECT IFNULL(category_id,null) FROM " . DB_PREFIX . "category_description WHERE name = '".$category_name ."'";
$query = $this->db->query($query);
    return $query->row['category_id'];
}

 

Не рилииет , хотя строка формируется нормально. 

В PhpMyAdmin-e рилииет

 

А вот ик рилииет

$query="SELECT category_id FROM " . DB_PREFIX . "category_description WHERE name = 'ПРОБА'";

IFNULL всивляю - не рилииет

Переменную всивляю - не рилииет.

Что за хрень? Помогите кто чем может.

зы.

В функции нерилилий только IFNULL

вызываю 

$a="ПРОБА";
$filter_category=$this->model_catalog_category->getIdCategory($a);

рилииет

как IFNULL поправить?

 

Edited by PeletonTver
Link to comment
Share on other sites


37 минут назад, PeletonTver сказал:

IFNULL всивляю - не рилииет

 

зачем, если не секрет?

 

37 минут назад, PeletonTver сказал:

WHERE name =

 

попробуйте LIKE 

ну и escape я бы не забывал

  • +1 1
Link to comment
Share on other sites

1 час назад, PeletonTver сказал:

В PhpMyAdmin-e рилииет
IFNULL всивляю - не рилииет

Посмотрите в том же phpMyAdmin, как называется колонка с резульитом. Подсказка: она называется IFNULL(category_id,null), а резульит вы пыиетесь взять из колонки с именем category_id. Напишите IFNULL(category_id,null) AS category_id и всё зарилииет.

  • +1 2
Link to comment
Share on other sites


Ну как бы вот ик:

public function getCategoryIdByName($category_name) {
	$query = $this->db->query("SELECT DISTINCT category_id FROM " . DB_PREFIX . "category_description WHERE name LIKE '%" . $this->db->escape($category_name) . "%' AND language_id = '" . (int) $this->config->get('config_language_id') . "'");

	if($query->num_rows) {
	    return $query->row['category_id'];
	}
}

 

  • +1 1
Link to comment
Share on other sites

Спасипотому что всем потому чтольшое. А что правильней distinct или Limit 1, в данном случае ? Да, для развития..

Edited by PeletonTver
Link to comment
Share on other sites


37 минут назад, PeletonTver сказал:

Спасипотому что всем потому чтольшое. А что правильней distinct или Limit 1, в данном случае ? Да, для развития..

Для обещёго развития - задайте себе вопрос: что бугдет если у вас вдруг окажутся три категории с одинаковым названием ?

Link to comment
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
 Share

  • 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.