views:

24

answers:

1

I have a list of dates stored in a MYSQL table, the idea is if the following field has valued 'completed' the row's date is unselectable in the jQueryUI datepicker. The dates are stored in the format YYYY-MM-DD.. how would I go about loading these 'completed' dates into a PHP array in a format for the datepicker to understand and disable them? JSON would be the obvious answer, I've spent the last couple of weeks getting to grips with it. Any example code of the jquery / php code would be greatly appreciated.

Many thanks in advance.

[ I have done research around the subject but it is not particularly well documented.. I've already got the datepicker showing valid days in a week. The jqueryUI datepicker seems to be able to do everything except make me a cup of tea. ]

EDIT: So I've managed to feed the array of dates with 'final' status through with JSON, I thought i'd provide the code if it helps anyone:

    <?php

    //connect to local db
    include('functions.php');
    connectLocal($localcon);

    //locate rows with status set to final
    $result = mysql_query("SELECT sendDate FROM my_table WHERE status='final'");

    // return corresponding dates as json array
    $i=0;
    while($row = mysql_fetch_array($result))
    {
        $confirmedSends[$i] = array ( "sendDate" => $row['sendDate']);
        $i++;
    }
    header('Content-type: application/json');
    $jsonConfirmedSends =  json_encode($confirmedSends); 
    echo $jsonConfirmedSends;
?>

This can retrieved with json in the form of a list of dates. The alert box pops up once for each date. About to get to work on presenting these to my datepicker array.

$.getJSON("get-disabled-dates.php",
function(data){
     $.each(data, function(index, completed) {
        alert(completed.sendDate);
    });
});
A: 

Try following code to match your situation which disables set of dates. You can get dates by using json from your mysql table using $.getJSON of jquery

 $(function() {
            $( "#pickdate" ).datepicker({
                dateFormat: 'dd MM yy',
                beforeShowDay: checkAvailability
                });

    })


    var $myBadDates = new Array("10 October 2010","21 October 2010","12 November 2010");

    function checkAvailability(mydate){
    var $return=true;
    var $returnclass ="available";
    $checkdate = $.datepicker.formatDate('dd MM yy', mydate);
    for(var i = 0; i < $myBadDates.length; i++)
        {    
           if($myBadDates[i] == $checkdate)
              {
            $return = false;
            $returnclass= "unavailable";
            }
        }
    return [$return,$returnclass];
    }

source : http://codingforums.com/showthread.php?t=206879

Paniyar