date picker dates from mysql

date picker dates from mysql

Hello everybody
I wanted to pass from mysql some dates to be unselectable with the date picker.
Here's my booked_dates.php file:

include("config.inc.php");
$db = mysql_connect($db_host, $db_user, $db_password);
if ($db == FALSE)
die ("Errore nella connessione. Verificare i parametri nel file config.inc.php");
mysql_select_db($db_name, $db)
or die ("Errore nella selezione del database. Verificare i parametri nel file config.inc.php");
mysql_set_charset('utf8',$db); 
$merchant_date = mysql_query("SELECT date_in FROM bookings");
while ($result = mysql_fetch_array($merchant_date))
{
$date_in = date("d-m-y", $result[date_in]);
$dates[] =  $date_in;
}
echo json_encode($dates);
?>

And here's my script:
<script>

var array = [<? echo json_encode($dates); ?>]
 
  $(function() {
$.datepicker.setDefaults(
  $.extend(
    {'dateFormat':'dd-mm-yy'},
    $.datepicker.regional['it']
  )
);
    $( "#from" ).datepicker({
beforeShowDay: function(date){
       var string = jQuery.datepicker.formatDate('dd-mm-yy', date);
       return [array.indexOf(string) == -1 ]
   }
    });
    $( "#to" ).datepicker({
      beforeShowDay: function(date){
       var string = jQuery.datepicker.formatDate('dd-mm-yy', date);
       return [ array.indexOf(string) == -1 ]
   }
    });
  });
  </script>

I'm working with the page:
http://www.labadiaroma.com/temp/book3.php

Bye, Rhino