db = new Database(); } function exists($priceset_id, $product_id) { $query = "SELECT * FROM ".$this->db->price_table." WHERE priceset_id='".$priceset_id."' AND product_id='".$product_id."'"; if(count($this->db->fetchRows($this->db->query($query))) > 0) return true; else return false; } function create($priceset_id, $product_id, $value) { $query = "INSERT INTO ".$this->db->price_table." VALUES('', '".$priceset_id."', '".$product_id."'"; for($i = 0; $i < count($value); $i++) $query .= ", '".$value[$i]."'"; $query .= ")"; $this->db->query($query); } function update($priceset_id, $product_id, $value) { $query = "UPDATE ".$this->db->price_table." SET "; $query .= "price='".$value[0]."' "; $query .= "WHERE priceset_id='".$priceset_id."' AND product_id='".$product_id."'"; $this->db->query($query); } function delete($price_id) { $query = "DELETE FROM ".$this->db->price_table." WHERE price_id='$price_id'"; $this->db->query($query); } function get($price_id = "", $col_names = array(), $search = "") { if($price_id == "") { if(count($col_names) == 0) $query = "SELECT * FROM ".$this->db->price_table; else { $query = "SELECT ".$col_names[0]; for($i = 1; $i < count($col_names); $i++) $query .= ", ".$col_names[$i]; $query .= " FROM ".$this->db->price_table; } if($search != "") $query .= " WHERE ".$search; $query .= " ORDER BY price_id ASC"; return $this->db->fetchRows($this->db->query($query)); } else { $query = "SELECT * FROM ".$this->db->price_table." WHERE price_id='".$price_id."'"; $query .= " ORDER BY price_id ASC"; return $this->db->fetchRows($this->db->query($query)); } } function getPrice($priceset_id, $product_id) { $query = "SELECT * FROM ".$this->db->price_table." WHERE priceset_id='".$priceset_id."' AND product_id='".$product_id."'"; return $this->db->fetchRows($this->db->query($query)); } } ?>