Ejemplo n.º 1
0
 public function __construct($id = -1)
 {
     if (is_null(self::$conn)) {
         self::$conn = mysqli_connect('localhost', 'root', 'osama', 'store');
     }
     if ($id != -1) {
         # to get all the products for a specific user
         $this->user_id = $id;
         $query = "select * from cart where user_id={$id}";
         $result = mysqli_query(self::$conn, $query);
         $data = [];
         while ($row = mysqli_fetch_assoc($result)) {
             $data[] = ['prod_id' => $row['prod_id'], 'qty' => $row['qty']];
         }
         // var_dump($data);
         return $data;
     }
 }