I have a script that will get the users current time. Then I pass this variable to PHP to display content on the site. When I first load the page the PHP does not display the query results until the page is reloaded. How can I get it to appear when a user first accesses the web page? I am using wordpress.
<script type="text/javascript">
<script src="jquery-3.2.1.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="http://www.developwww.com/js-cookie-1.5.1/src/js.cookie.js"></script>
<script>
function client_date() {
var d = new Date();
var month = new Array();
month[0] = "January";
month[1] = "February";
month[2] = "March";
month[3] = "April";
month[4] = "May";
month[5] = "June";
month[6] = "July";
month[7] = "August";
month[8] = "September";
month[9] = "October";
month[10] = "November";
month[11] = "December";
var x = month[d.getMonth()];
var y=d.getDate();
var z=d.getFullYear();
var s=x+" "+y+","+z;
return s ;
}
var day = Math.round((new Date().setHours(23) - new Date(new
Date().getYear()+1900, 0, 1, 0, 0, 0))/1000/60/60/24);
$.cookie("date", client_date());
$.cookie("day", day);
</script>
Here is the PHP
$dayYear=$_COOKIE["day"];
$date=$_COOKIE["date"];
echo $date ."<br> " ;
$query = " select C.book,B.fchapter, B.lchapter, B.fverse ,B.lverse
FROM readingplan B, biblebooks C WHERE B.id = $dayYear and
C.id=B.fbook";
And then I have it display the results.