Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

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>
share|improve this question
    
Have you read JQuery UI Datepicker's documentation to find out what the expected format is? What precise problem have you found? – Álvaro González Aug 2 '13 at 9:48
    
I have, and " var enableDays = ["07-08-2013", "08-08-2013"]; " is the correct format. And the datepicker is working with any hardcoded values I like. I just cant work out how to dynamically bring that data in from the array returned by the sql query .... – user2014175 Aug 2 '13 at 9:51
    
Possible duplicate of MySQL date format DD/MM/YYYY select query?. So it expects a string in either DD-MM-YYYY or MM-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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.