N
N
Nikolai Kovalevsky2017-04-25 08:23:45
PHP
Nikolai Kovalevsky, 2017-04-25 08:23:45

What does the rows function do in this particular case?

Good morning. I deal with the issue of generating CNC url in opencart, I found a suitable code on the net and set it up. But I do not quite understand one of its functions, namely rows. What does it return in a particular case? I would be grateful for clarifications.

public function getProductPath($product_id)
  {
    $category_id = $this->db->query("SELECT category_id FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'");
    if (isset($category_id->rows[0]['category_id']) && ($category_id->rows[0]['category_id'] != 0)) {
      $parent_id = $this->db->query("SELECT parent_id FROM " . DB_PREFIX . "category WHERE category_id = '" . (int)$category_id->rows[0]['category_id'] . "'");
      if (isset($parent_id->rows[0]['parent_id']) && ($parent_id->rows[0]['parent_id'] != 0)) {
        $category = $parent_id->rows[0]['parent_id'] . "_" . $category_id->rows[0]['category_id'];
        $path_id_2 = $this->db->query("SELECT parent_id FROM " . DB_PREFIX . "category WHERE category_id = '" . $parent_id->rows[0]['parent_id'] . "'");
        if (isset($path_id_2->rows[0]['parent_id']) && ($path_id_2->rows[0]['parent_id'] != 0)) {
          $category = $path_id_2->rows[0]['parent_id'] . "_" . $parent_id->rows[0]['parent_id'] . "_" . $category_id->rows[0]['category_id'];
          $path_id_3 = $this->db->query("SELECT parent_id FROM " . DB_PREFIX . "category WHERE category_id = '" . (int)$path_id_2->rows[0]['parent_id'] . "'");
          if (isset($path_id_3->rows[0]['parent_id']) && ($path_id_3->rows[0]['parent_id'] != 0)) {
            $category = $path_id_3->rows[0]['parent_id'] . "_" . $path_id_2->rows[0]['parent_id'] . "_" . $parent_id->rows[0]['parent_id'] . "_" . $category_id->rows[0]['category_id'];
            $path_id_4 = $this->db->query("SELECT parent_id FROM " . DB_PREFIX . "category WHERE category_id = '" . (int)$path_id_3->rows[0]['parent_id'] . "'");
            if (isset($path_id_4->rows[0]['parent_id']) && ($path_id_4->rows[0]['parent_id'] != 0)) {
              $category = $path_id_4->rows[0]['parent_id'] . "_" . $path_id_3->rows[0]['parent_id'] . "_" . $path_id_2->rows[0]['parent_id'] . "_" . $parent_id->rows[0]['parent_id'] . "_" . $category_id->rows[0]['category_id'];
            }
          }
        }
      } else {
        $category = $category_id->rows[0]['category_id'];
      }
    } else {
      $category = false;
    }
    return $category;
  }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
web-mechanic, 2017-04-25
@Silert

Open the /system/library/db/mysqli.php class and you will see everything there. Actually, you will study opencart from the inside, looking into the scripts

E
Eugene, 2017-04-25
@Eugeny1987

it's not a function, it's a property of an object in the form of an array, 0 means the first element of the array

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question