how to pass an array from PHP

136 views
Skip to first unread message

volderon 99

unread,
Aug 4, 2016, 7:12:55 AM8/4/16
to jquery week calendar
calehdar.php


function read_event($start,$end){

mysql_query("SET NAMES 'utf8'");
$query = "SELECT * FROM events";
$result = mysql_query($query);
$strok=mysql_num_rows($result);
$i=0;
if (!$result) {
echo "DB Error, could not query the database\n";
echo 'MySQL Error: '.mysql_error();
exit;
}

$events = array();
echo '{events:['."\n";

while ($row = mysql_fetch_assoc($result)) {
$eventArray['id'] = $row['id'];
$eventArray['start'] = date('Y',$row['start']).", ".(date('m',$row['start'])-1).", ".date('d, H, i',$row['start']);
$eventArray['end'] = date('Y',$row['end']).", ".(date('m',$row['end'])-1).", ".date('d, H, i',$row['end']);
$eventArray['title'] = $row['title'];
$eventArray['body'] = $row['body'];
$eventArray['user_id'] = $row['user_id'];

$events[] = $eventArray;

echo '{"id":'.$events[$i]['user_id'].',"start": new Date('.$events[$i]['start'].'),
"end": new Date('.$events[$i]['end'].'),"title":"'.$events[$i]['title'].'",
"body":"'.$events[$i]['body'].'","userId":'.$events[$i]['user_id'].'}';

if ($strok > 1) {
echo ',';
$rez=$rez.',';
}
$strok--;
$i++;
}
echo ']}';
}


There is a script PHP returns a string:

{events:[ {"id":0,"start": new Date(2016, 7, 04, 11, 00), "end": new Date(2016, 7, 04, 11, 45),"title":"ccc", "body":"bbb","userId":0}]}

But in data: this miss



 data:

function(data) {
$.ajax(
{
url: 'calendar.php?op=read_event',
dataType: 'html',
success: function (data) {
var events = eval(data);
return(events);
}

});

}


});

Tell me how to get the data from PHP.

Reply all
Reply to author
Forward
0 new messages