Note that there are some explanatory texts on larger screens.

plurals
  1. POHighlighting date with event in datepicker from mysql database
    primarykey
    data
    text
    <p>Trying to make dates from my database to be "highlighted" in the datepicker using jquery and php. I have looked everywere to find something to help me...</p> <p>This is the code I am using at the moment. Notice that it has a onSelect state that makes it possible to click on a date and get an event from the database and print it to a div, this works and now i want to make the dates with events highlighted too..</p> <pre><code>$(document).ready(function() { var SelectedDates = {}; $.getScript('eventdates.php', function(eventsdate) { eventsdate; }); $("#kalender").datepicker({ firstDay: 1, dayNamesMin: ['Sö', 'Må', 'Ti', 'On', 'To', 'Fr', 'Lö'], monthNames: ['Januari', 'Februari', 'Mars', 'April', 'Maj', 'Juni', 'Juli', 'Augusti', 'September', 'Oktober', 'November', 'December'], dateFormat: "yy-mm-dd", beforeShowDay: function(date) { var Highlight = SelectedDates[date]; if (Highlight) { return [true, "Highlighted", Highlight]; } else { return [true, '', '']; } }, onSelect: function(dateText, inst) { var myDate = new Date(dateText); var newFormat = $.datepicker.formatDate('yy-mm-dd', myDate); $.ajax({ url: 'events.php', type: 'POST', dataType: 'json', data: {selectedData: newFormat}, success: function(result) { if (result.date === newFormat) { $('#event').html(result['date'] + " " + result['event']); } else { $('#event').html(result['none']); } } }); } }); });​ </code></pre> <p>eventdates.php</p> <pre><code>&lt;?php include_once ('connect.php'); $sql = mysql_query("SELECT * FROM `events`"); while ($row = mysql_fetch_array($sql)) { echo "SelectedDates[new Date('{$row['date']}')] = new Date('{$row['date']}')&lt;br/&gt;"; } ?&gt; </code></pre> <p>events.php</p> <pre><code>&lt;?php include_once ('connect.php'); if (isset($_POST['selectedData'])) { $sql2 = mysql_query("SELECT * FROM `events` WHERE `date`='{$_POST['selectedData']}'"); $row2 = mysql_fetch_array($sql2); if ($row2['date'] == $_POST['selectedData']) { $sql = mysql_query("SELECT * FROM `events` WHERE `date`='{$_POST['selectedData']}'"); while ($row = mysql_fetch_array($sql)) { $data = array( "date" =&gt; $row['date'], "event" =&gt; utf8_encode($row['event']) ); echo json_encode($data); } } else { $data = array( "none" =&gt; "Inget event denna dag!" ); echo json_encode($data); } } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload