<?php

include('db_con.php');


if(isset($_POST['btn_action']))


{

	if($_POST['btn_action'] == 'lp_rate')

	{

		/// update Last purchase Rate

		$sql = "select item_id from items order by item_id asc";
 $statement = $connect->query($sql);
 $result = $statement->fetchAll();
 foreach ($result as $row) {

   $item_no = $row['item_id'];

   $sql = "select d.rate from purchase_detail d, purchase m where m.p_id=d.p_id and  d.item_no = '".$item_no."' order by m.dated desc LIMIT 1";
    $statement = $connect->query($sql);
    $lp_rate = $statement->fetchColumn();
    $sql = "update items set lp_rate = '".$lp_rate."' where item_id = '".$item_no."'";
    $statement = $connect->query($sql);


 }

}
echo 'Redirecting';
	

}


?>