I have a JavaScript function that creates a <div>
. It uses Ajax to access the database so and creates a different <div>
if the dates match. But now I want to take the 'date' variable from the JavaScript <div>
that matches the database and send it through another PHP function that gets all entries with that date and echoes them out to a JQuery pop-up. What am I’m doing wrong and is there an easier way than the code below?
First AJAX call:
beforeMonth:function(date)
{
$.ajax({
type: "GET",
url: "getCalendarEvents.php",
dataType: "json",
data: "date="+date,
async: false, //stop rendering the calender until eventdates is changed.
success: function(json){
$.fn.ical.changeEventDates(json); //this function changes the eventdates
}
})
}
getCalendarEvents.php
include ("Includes/dbConnect.php");
$_GET['date'];
$query2 = "SELECT * FROM events";
$checkevent = mysqli_query($cxn,$query2) or die("Couldn't execute query!");
$dates = array();
while ($row2 = mysqli_fetch_array($checkevent))
{
$eventDate = $row2['eventDate'];
$eventName = $row2['eventName'];
$eventHost = $row2['host'];
$dates[$eventDate] = array('title' => $eventName, 'desc' => $eventHost);
}
echo json_encode(array("dates" => $dates));
exit;
JavaScript in a separate file (just the function that creates the <div>
):
if(!datejson)
{
options.beforeDay(formatdate);
$("table tr:last, obj").append("<td id = '"+formatdate+"'>"+i+"</td"); //add day
}
else
{
options.beforeDay(formatdate);
$("table tr:last, obj").append("<td class='date_has_event' id = '"+formatdate+"' name='"+formatdate+"'>"+i+"<div class='title'><a href='#' class='popup'><img src='images/facebook.png' class='popup'/></a></div>"+"<div class='events'><ul><li><span class='desc'>"+datejson.desc+"</span></li></ul></div></td"); //add day
}
PHP in the HTML:
<div id="popupContact">
<a href="#" id="popupContactClose">Close X</a>
<div id="popupHeader">Events occurring on</div>
<?php
include ("Includes/dbConnect.php");
$calendarDate=$_GET['formatdate']
$query = "SELECT * FROM events WHERE eventDate='$calendarDate'";
$check = mysqli_query($cxn,$query) or die("Couldn't execute query!");
while($row = mysqli_fetch_array($check))
{
$id = $row['eventID'];
echo "<div class='submit_event_list'><a href='individual_event_page_main.php?id=$id'>";
echo $row['eventName'];
echo " | " . $row['venue'];
echo " | " . $row['eventDate'];
echo "</a></div>";
echo "<br />";
}
mysqli_close($cxn);
?>
</div>