I have created a function where the query is to get details daily monthly and yearly. The data is displayed correctly within the file, I need to copy it to a $_SESSION as this data will be used in other files. The data is not being copied and works only in that file. Help please
function sharecal($date_start,$date_end) {
$profit=0;
$conn = mysqli_connect('localhost', 'root', '12May@61', 'investments');
$query="SELECT * from sale WHERE sale_date BETWEEN '$date_start' AND '$date_end'";
$result = mysqli_query($conn, $query) ;
while ($row = mysqli_fetch_assoc($result)) {
$id=$row['id_holding'];
$sale_qty=$row['qty_sold'];
$query_buy="SELECT * FROM buy WHERE id_holding=$id";
$result_buy = mysqli_query($conn, $query_buy) ;
while ($row_buy = mysqli_fetch_assoc($result_buy)) {
$profit+=($row['sale_rate']-$row_buy['buy_rate'])*$sale_qty;
}
}
echo $date_start ."--".$date_end . "Rs.: ";
echo $profit;
}
echo "Daily";
$date_start=$date_end=date("Y-m-d");
sharecal($date_start,$date_end);
echo $profit; (does not work)
$_SESSION['daily']=$profit; (does not work)
echo "Monthly";
$date_start=date("$year-$month-01");
$date_end=date("$year-$month-31");
//echo $date_start.$date_end."<br>";
sharecal($date_start,$date_end);
echo "<br>";