1

In my PHP i have the following PDO query:

$findEventStartdates = $pdo->prepare('SELECT startdate FROM calendar WHERE username=?'); 

//execute query with variables
$findEventStartdates->execute([$username]);


($eventStartdates = $findEventStartdates->fetchAll(PDO::FETCH_COLUMN));

If i print that query i get the following results

Array ( [0] => 14 april 2017 [1] => 25 april 2017 [2] => 1 april 2017).

My question is, how can i use this array to then highlight those dates in the datepicker. I've looked for ages on how to turn that array into variables in jquery and then highlight those days in the datepicker but can't seem to find it anywhere.

Thanks for any help.

Devid Farinelli
  • 7,514
  • 9
  • 42
  • 73
crapAtCode
  • 35
  • 10
  • First you should convert your dates to the proper format, check DateTime class in PHP. Then check this topic: http://stackoverflow.com/questions/2385332/highlight-dates-in-specific-range-with-jquerys-datepicker – vaso123 Apr 03 '17 at 09:28

1 Answers1

0

I worked this out. After you perform the PDO you need to have some inline javascript that basically turns the array into the jquery variable. from there you can use beforeShowDay to pick up that variable and highlight the days:

$findEventStartdates = $pdo->prepare('SELECT startdate FROM calendar WHERE username=?'); 

//execute query with variables
$findEventStartdates->execute([$username]);


($eventStartdates = $findEventStartdates->fetchAll(PDO::FETCH_COLUMN));

?>

<script type="text/javascript">
    //Assign php generated json to JavaScript variable
    var event = <?php echo json_encode($eventStartdates); ?>;
</script>

<?php    
crapAtCode
  • 35
  • 10