I'm currently trying to populate an inline jquery datepicker with only the dates that are held in an array I'm pulling from an sql database. My code is below. It would be a great help if somebody could point out how to correctly parse the array so that the "enableDays" array in the jQuery function is populated with the data returned from the sql query. Any help would be greatly appreciated. Thanks
<?php
// connection is set up above
mysql_connect("$host", "$username", "$password")or die("Connection to database: Failed");
mysql_select_db("$db_name")or die("Connection to table: Failed");
$sql="SELECT DISTINCT date FROM xcp_results WHERE zzx='TRD' ORDER BY date DESC";
$result=mysql_query($sql);
$array = mysql_fetch_array($result);
$count=mysql_num_rows($result);
?>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Calender Control Test</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
jQuery(function(){
var enableDays = ["07-08-2013"];
function enableAllTheseDays(date) {
var sdate = $.datepicker.formatDate( 'dd-mm-yy', date)
console.log(sdate)
if($.inArray(sdate, enableDays) != -1) {
return [true];
}
return [false];
}
$('#datepicker').datepicker({dateFormat: 'dd-mm-yy', beforeShowDay: enableAllTheseDays});
})
</script>
</head>
<body>
<div id="datepicker"></div>
</body>
</html>
DD-MM-YYYY
orMM-DD-YYYY
format (I suppose you know which one). There're endless dupes on how to format a date in MySQL (and how to format a date in PHP). I've pointed you to a random one that has a correct answer. – Álvaro González Aug 2 '13 at 10:37