hi friends
I have added a code for view_count for products. I have written a code as below
kindly tell me, how to fix my issue. table name : products and colum (view_count) i also have added view_count as date memeber as well.
public function get_product($view_update = FALSE) {
$obj_db = self::obj_db();
$query = "select * "
. "from products"
. "where productID = '$this->productID'";
$result = $obj_db->query($query);
if($obj_db->errno){
//echo("ss");
//die;
throw new Exception("Select product Error - $obj_db->error -$obj_db->errno");
}
if($result->num_rows == 0){
throw new Exception("Product not found");
}
$data = $result->fetch_object();
if($view_update){
$data->view_count++;
$query_update = "update products set "
. "view_count = view_count+1 "
. "where `productID` = '$this->productID'";
$r2 = $obj_db->query($query_update);
if($obj_db->affected_rows == 0){
//nothing updated
}
}
$this->productID = $data->productID;
$this->product_name = $data->product_name;
$this->description = $data->description;
$this->product_features = $data->product_features;
$this->product_image = $data->product_image;
$this->unit_price = $data->unit_price;
$this->quantity = $data->quantity;
$this->view_count = $data->view_count;
$this->brand->brandID = $data->brandID;
$this->brand->brand_name = $data->brand_name;
$this->brand->brand_image = $data->brand_image;
}