Hi,
I am very new to coding in php and javascript, so please forgive me if this is a daft question…
I am basically trying to get a recurring date set up on a website, based on an initial date given by a user. This is to show bin collections which happen fortnightly. I have successfully brought the data in from the database of when the user has said the first bin collection happens, but I am having troubles getting the variable that holds this information to then feed into the javascript.
I know that the line ‘var firstDayOfCycle = new Date(2011, 5, 10);’ will work, so my idea was to use php to gather the same date string and then insert it, however this isn’t working. I know that the line ‘echo $NewTimeofNextBinCollection;’ is returning ‘2016, 8, 26’ which is close to what I want it to feed into the javascript. (I know that the month needs reduced by 1 though). The current output is that the javascript seems to think that the current day is the day the bin collection happens, so it’s not picking up the variable of $NewTimeofNextBinCollection.
Does anyone know how to resolve this? It’s driving me slowly mad trying to figure out what to do!
Here’s the code:
[php]<?php session_start(); ?>
<?php include 'functions.php'; if ($stmt = $mysqli->prepare("SELECT BinCollectionDate FROM building WHERE Buildingid=?")) { // opening prepare statement (2) $stmt->bind_param("s", $BuildingID); $BuildingID = $_SESSION["usersBuildingID"]; $stmt->execute(); //echo $_SESSION["usersBuildingID"]; $stmt->store_result(); $stmt->bind_result($BinCollectionDate); if ($stmt->num_rows > 0) { //opening rows (3) $stmt->fetch(); } // closing rows (3) echo $BinCollectionDate; if ($BinCollectionDate == 0) { //if no data, show button to add data echo("No Bin Collection information set up yet.
"); } else { //opening else (6) echo ""; //echo $BinCollectionDate; $time = strtotime(stripslashes($BinCollectionDate)); //echo $time; $time = ($time . '-1 month'); $NewTimeofNextBinCollection = (date("Y, n, j",$time)); echo $NewTimeofNextBinCollection; echo ""; //echo date("y, m, d",$time); } //closing else (6) $stmt->close(); } //closing prepared statement (2) $mysqli->close(); //$DateOfNextBinCollection = date("y-n-j",$time); //$DateOfNextBinCollection = date("y-m-d",$time); //echo $DateOfNextBinCollection; //$DateOfNextBinCollectionUNIXCode = strtotime($DateOfNextBinCollection . ' - 1 month'); //$DateOfNextBinCollectionUNIXCode = strtotime($DateOfNextBinCollection); //echo $DateOfNextBinCollectionUNIXCode; ?>[/php]