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>
share|improve this question
   
Why don't you let the same php function that is called with AJAX generate the popup? – Mikey Mar 21 '12 at 19:48
Currently the AJAX is calling from the database in json format so not sure how to do both? – rudawg Mar 21 '12 at 19:54
What isn't working? The javascript you posted looks irrelevant; are you wondering how to write the AJAX call for that PHP block? – nkorth Mar 21 '12 at 20:13
no i need to take the 'formatdate' variable in the div created by Javascript, and use it in a php function if thats possible?? – rudawg Mar 21 '12 at 20:35
It would help if you posted the response body for the getCalendarEvents.php. – ThoriumBR Mar 21 '12 at 20:40
show 3 more comments

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.