before start i wanna say, i have seen already all of the similar question but i didn't get answer for my problem and sorry if my question is duplicate
I want to calculate discount of product price in product details page but I've got title problem, this website is developed base on PHP mvc
this is my function in main model:
function caluclateDiscount($price,$discount){
$price_discount=((100-$discount)*$price)/100;
$total_price=$price-$price_discount;
return [$price_discount,$total_price];
}
in product model class:
function productInfo($id){
$sql="select * from tbl_product where id=:product";
$stmt=self::$conn->prepare($sql);
$stmt->bindParam(':product',$id);
$stmt->execute();
$result=$stmt->fetch();
$price=$result['price'];
$discount=$result['discount'];
$price_calculate=$this->caluclateDiscount($price,$discount);
$result['price_discount']=$price_calculate[0];
$result['total_price']=$price_calculate[1];
return $result;
}
in the product Controller:
function index($id){
$productInfo=$this->model->productInfo($id);
$data=['p_info'=>$productInfo];
$this->view('product/index',$data);
}
and finally in price field in product page:
<span> <?= $special=$data['p_info']; $special['price_discount']; ?> </span>