In this function below i am calling a function using from_date and to_date in iteration. here for each iteration i am updating the from date value and when it comes to $to_date
i am calculating the day from which it returns the date from now. for example the sharing_basis returns values like 2 weeks, 5 weeks....
for example:
I am using $to_date = date("Y-m-d", strtotime("+".$sharing_basis));
to get the value of $to_date. the to_date returns date of the given number of weeks from now.
but here it is returning the same date everytime. i want to calculate $to_date
based on $from_date
lets say, for first iteration
$from_date = 2016-12-31
$to_date = $to_date = date("Y-m-d", strtotime("+5 weeks"));
I want to get the day date of 5 weeks from $from_date.
How can i do this?
function createSharingdates($productId){
$startdate = getStartdate($productId);
$sharing_basis = getSharingBasis($productId);
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT user_id FROM orders WHERE product_id='$productId' ORDER BY order_datetime";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$user_id = $row["user_id"];
$from_date = $startdate;
foreach ($user_id as $userid) {
$to_date = date("Y-m-d", strtotime("+".$sharing_basis));
addSharingDates($product_id,$userid,$fromdate,$to_date);
$from_date = $to_date
}
} else {
return false;
}
$conn->close();
}