0

I have this error : how to resolve ? Tk

Notice: Undefined index: price_group_view in /......../Products.php on line 124

line 124 is : return $this->getData()[$obj];

there the elements :

    private function setData() {

      if ($this->customer->getCustomersGroupID() != 0) {
        $Qproducts = $this->db->prepare('select  p.products_id,
                                                  p.products_tax_class_id,
                                                  p.orders_view,
                                                  p.products_view,
                                                  p.products_archive,
                                                  p.products_quantity,
                                                  g.customers_group_price,
                                                  g.price_group_view,
                                                  g.orders_group_view,
                                                  g.products_group_view
                                        from :table_products p left join :table_products_groups g on p.products_id = g.products_id
                                        where p.products_status = 1
                                        and g.customers_group_id = :customers_group_id
                                        and g.products_group_view = 1
                                        and p.products_id = :products_id
                                       ');

        $Qproducts->bindInt(':products_id', $this->getID() );
        $Qproducts->bindInt(':customers_group_id', $this->customer->getCustomersGroupID() );

      } else {

        $Qproducts = $this->db->prepare('select products_id,
                                                products_tax_class_id,
                                                products_quantity,
                                                orders_view,
                                                products_view,
                                                products_archive,
                                                products_tax_class_id
                                        from :table_products
                                        where products_status = 1
                                        and products_view = 1
                                        and products_id = :products_id
                                       ');

        $Qproducts->bindInt(':products_id', $this->getID() );
      }

      $Qproducts->execute();

      return $Qproducts->fetch();
    }

    public function getData()  {
      return $this->setData();
    }

===> returns a single element of the data array
    public function get($obj)  {
      return $this->getData()[$obj];
    }
Denis
  • 45
  • 5

1 Answers1

0

I would do some error checking around

  $Qproducts->execute();

  return $Qproducts->fetch();

If $Qproducts->fetch() is empty after the query is executed, then a subsequent access like "return $this->getData()[$obj];" will surely throw such an error.

You can test for an empty array prior to the call.

bcperth
  • 2,191
  • 1
  • 10
  • 16