JQuery datepicker, disable dates from MYSQL

I have a list of dates stored in a MYSQL table, the idea is that the next value of the "completed" field in the date string is not selected in the jQueryUI datepicker. Dates are stored in the format YYYY-MM-DD .. how can I load these "completed" dates into a PHP array in a format that a date picker can understand and disable? JSON would be the obvious answer, I have spent the last couple of weeks to handle this. Any jquery / php code code would be greatly appreciated.

Thank you very much in advance.

[I did research on this subject, but it is not particularly well documented. I already have a date picker showing valid days per week. It seems that jqueryUI datepicker is capable of doing everything except making a cup of tea. ]

EDIT: Thus, I managed to pass an array of dates with the “final” status using JSON, I thought I would provide the code if it helps someone:

    <?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 be obtained using json as a list of dates. A warning field appears once for each date. About working on representing them in my datepicker array.

$.getJSON("get-disabled-dates.php",
function(data){
     $.each(data, function(index, completed) {
        alert(completed.sendDate);
    });
});
+3
source share
1 answer

Try executing code that matches your situation, which disables the date set. You can get dates using json from your mysql table using $ .getJSON 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

+2
source

Source: https://habr.com/ru/post/1771288/


All Articles