0

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>
Kenny Linsky
  • 1,726
  • 3
  • 17
  • 41
rudawg
  • 73
  • 1
  • 1
  • 11
  • Why don't you let the same php function that is called with AJAX generate the popup? – Frank van Wijk 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
  • This question is extremely vaguel can you better describe what you're trying to do? Do you have examples? This seems more like something you're trying to do in an overly complicated way while it might be very simple.... – sg3s Mar 21 '12 at 20:43
  • posted getCalendarEvents.php there if it helps?? Thats what im trying to figure out sg3s, im trying to take the 'formatdate' variable in the 'date_has_event' div and use it in a php function to call data from the database that corresponds to that date – rudawg Mar 21 '12 at 20:53
  • possible duplicate of [How to pass javascript variables to php](http://stackoverflow.com/questions/1917576/how-to-pass-javascript-variables-to-php) – PeeHaa Mar 26 '12 at 22:11

0 Answers0