FullCalendar just wont display JSON feed - php

sorry to post this but have been struggling now for 8 days and really hope someone can help as I am at the end. I have json.html & xxjson-events.php in same directory, both file content posted below.
json.html
<script type="text/javascript">
$(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
$('#calendar').fullCalendar({
eventSources: [
// your event source
{
url: '/xxjson-events.php' // use the `url` property
}
]
});
</script>
xxjson-events.php
<?php
mysql_select_db($database_ghl_portal, $ghl_portal);
$query_rsXXCal = "SELECT * FROM events";
$rsXXCal = mysql_query($query_rsXXCal, $ghl_portal) or die(mysql_error());
$row_rsXXCal = mysql_fetch_assoc($rsXXCal);
$totalRows_rsXXCal = mysql_num_rows($rsXXCal);mysql_select_db($database_ghl_portal, $ghl_portal);
$query_rsXXCal = "SELECT * FROM events";
$rsXXCal = mysql_query($query_rsXXCal, $ghl_portal) or die(mysql_error());
$row_rsXXCal = mysql_fetch_assoc($rsXXCal);
$totalRows_rsXXCal = mysql_num_rows($rsXXCal);
$result = mysql_query($query_rsXXCal) or die(mysql_error());
while($row = mysql_fetch_assoc($result)){
$eventsArray = array();
$eventsArray['title'] = $row['title'];
$eventsArray['start'] = $row['start_date'];
$eventsArray['end'] = $row['end_date'];
}
echo json_encode($eventsArray)
?>
json-events.php viewed in browser shows:
{"title":"TEST","start":"2012-02-23 00:00:00","end":"2012-02-24 00:00:00"}
The calendar shows on page however data does not pull through to the calendar? has anyone any ideas at all why this could be please, really struggling with this and need to sort. I thought it may be the datetimestamp showing 00:00:00 but changed this with no success?
If it helps anyone I have uploaded a zip containing 3 files to see if it works for anyone else? http://ghldatastream.co.uk.predns.ourwindowsnetwork.com/fullcal_json.zip
Thanks

Your start and end date have to be in IETF, ISO8601 or UNIX timestamp format - see http://arshaw.com/fullcalendar/docs/event_data/Event_Object/

Related

How to get system date and time instead of internet's PHP

I am working on a website which reserves lot for clients. Lot reserved has expiration date. In localhost, everything works fine. The system date and time is what my website is getting. But when I tested it online (I uploaded my website) it's not getting the system date and time.
$d = date('d M Y h:i A'); //TODAYS DATE---> this doesnt change when I change my PC's date and time
$curdate = strtotime($d)*1000;
echo $d;
$sql = "SELECT * FROM reservation";
$res = $conn->query($sql);
foreach ($res as $row) {
$exp = strtotime($row['expiration'])*1000;
$lot = $row['lot'];
$sqli = "SELECT * FROM reservation WHERE ".$curdate." >= ".$exp." AND status='reserved'";
$resu = $conn->query($sqli);
foreach ($resu as $ro) {
$id = $ro['reserve_id'];
$sl = "DELETE FROM reservation WHERE reserve_id='$id'";
$conn->query($sl);
$l = substr($ro['lot'], 1);
echo "<script>$(document).find('#_".$l."').css({'fill':'#848484'});</script>";
}
}
PHP uses the time for the machine it's running on "Server", still you can get the time from the client machine using javascript/jquery -ajax call like :
var TimeNow = new Date();
$.ajax({
url : url,
data : {date : TimeNow}
});

Error with my dojo ajax php request

Im trying to use a dojo ajax function to call a PHP file that then returns the contents of a DB table in JSON format.
My function:
var _getWeatherInfo = function(){
dojo.xhrget({
url: "PHP/weather.php?ntown=" + _ntown,
handleAs: "json",
timeout: 5000,
load: function(responce, details) {
_updateWeathertData
},
error: function(error_msg, details) {
_handleError(error_msg);
}
});
}
My PHP:
<?php include('configHome.php'); ?>
<?php
$ntown = $_GET['ntown'];
$weather = array();
$query="SELECT * FROM `weather` WHERE `town` = '$ntown'";
$result=mysql_query($query);
while($row = mysql_fetch_row($result)) {
$weather[] = $row[0];
}
echo json_encode($weather);
mysql_close();
?>
When using this code I am getting an error message saying that "$ntown = $_GET['ntown'];" is an undefined index. I have tried removing the index all together and using an actual value in the select statement (i.e. SELECT * FROM weather WHERE town = 'Auckland') but all I get back is the value i enter ["Auckland"], and not the 3 other values that are meant to be returned, ["Auckland", "Sunny", "8", "14"].
Any ideas? I can try add more info if needed. Thanks!
There are some other issues with your code, but to get to the one you are asking the question about. You have this:
while($row = mysql_fetch_row($result)) {
$weather[] = $row[0];
}
What you are doing is just taking the first value of the row (of which there is probably only one, and just sending that back. This is what you need:
$weather = mysql_fetch_row($result);

Why do I get "Null" in MySQL database? Flash pro cs6

I'm trying to update a flash movie quiz that records names and question answers - I did not write the original application. The quiz works, except that it replaces the name with null when recording data. All the other records work fine. I have deleted out the res2 - res12 just to shorten it up, they all work well.
Im using Flash Pro CS6
The code is in AS3
Thanks in advance for any light you can shed on this.
From Name input page of the quiz. participname is the text field input:
stop();
btn1.addEventListener(MouseEvent.MOUSE_UP,function():void {
var Name:String=participname.text.toString();
gotoAndPlay(3);
});
From the last page of the quiz
sendData();
function sendData(){
var messages:URLRequest = new URLRequest("./insertresult.php")
messages.method = URLRequestMethod.POST
var posts:URLVariables = new URLVariables()
posts.Name = Name
posts.DateCurrent = dtFormatted
posts.Res01 = res01
messages.data = posts
trace(posts);
var loader:URLLoader = new URLLoader()
loader.dataFormat = URLLoaderDataFormat.TEXT
// loader.addEventListener(Event.COMPLETE, dataOnLoad)
loader.load(messages)
trace(messages);
From the insertresult.php:
<?php
//Capture data from $_POST array
$name = $_POST['Name'];
$date = $_POST['DateCurrent'];
$res1 = $_POST['Res01'];
/* if(!$name ) {
echo "no input using default values <br>";
$name = 'deleteme';
}*/
$connect = mysql_connect("mydatabase");
mysql_select_db ("PAlogindatabase", $connect);
$result = mysql_query("INSERT into rhymeoddity1 (name,date,res1) values ('$name','$date','$res1')");
if($result) echo "writing=Ok&";
else echo "writing=Error";
?>
Can you check that the actionscript is actually reading and setting the Name properly before posting the data?
I sorted out the problem, i believe that this bit of the code was hiding away the var myname
stop();
btn1.addEventListener(MouseEvent.MOUSE_UP,function():void {
var myname:String=participname.text.toString();
gotoAndPlay(3);
}
);
i have replaced this with this and it is working fine now.
stop();
var myname:String = "";
btn1.addEventListener(MouseEvent.MOUSE_UP,function():void {
myname = participname.text;
gotoAndPlay(3);
}
);
If someone can explain what the difference is so i can understand

jQuery causing my php to break

I'm working on an online booking system, so I have a php script that receives a date and will output an array of possible timeslots that are free on that date. I'm trying to make it so that when closing the datepicker it sends the variables to the file and retrieves the result. At the moment the submit button also leads to the php file, and will show me available slots when I choose a date. The php part works, but when I add events to the datepicker it won't submit any variables to the php file. I think this is also the cause that when I add another load.('input_date.php'); I get the full timeslot list caused by the if(isset... Can anyone tell me why jQuery is ruining my variable posting? Thanks in advance..
$(document).ready(function() {
$("#dates").load('input_date.php');
$("#datepicker").datepicker({onClose: function() {
$.post("input_date.php", $('#datepicker').serialize());
alert(1);
}});
});
This is the php file:
<?php
include('connection.php');
error_reporting(0);
$treatment = $_POST['treatment'];
$bookdate = $_POST['bookdate'];
if(isset($treatment) && isset($bookdate)){
$exp = explode("-", $bookdate);
//determine what day of the week it is
$timestamp = mktime(0,0,0,$exp[1],$exp[0],$exp[2]);
$dw = date( "w", $timestamp); // sun0,mon1,tue2,wed3,thur4,fri5,sat6
echo $dw."weekday"; //week day
echo"<br/>";
//find bookings with same date
$q = mysql_query("SELECT BOOK_SLOT_ID FROM BOOKINGS WHERE BOOK_DATE='$bookdate'");
//make array of booking slots
$array1 = array();
while ($s = mysql_fetch_array($q)) {
$array1[] = $s['BOOK_SLOT_ID'];
}
$q2 = mysql_query("SELECT SL_ID FROM SLOTS");
//make array of all slots
$array2 = array();
while ($s2 = mysql_fetch_array($q2)) {
$array2[] = $s2['SL_ID'];
}
//remove bookings from all slots
$arr_res = array_diff($array2, $array1);
//make selectable options of results
echo "<SELECT>";
foreach($arr_res as $op){
$r = mysql_query("SELECT SL_TIME FROM SLOTS WHERE SL_ID='$op'");
$q3 = mysql_fetch_array($r);
echo "<OPTION value=".$op.">".$q3['SL_TIME']."</OPTION>";
}
echo "</SELECT>";
}else{
$else = mysql_query("SELECT * FROM SLOTS");
echo "<SELECT>";
while($array_else = mysql_fetch_array($else)){
echo "<OPTION value=".$array_else['SL_ID'].">".$array_else['SL_TIME']."</OPTION>";
}
echo "</SELECT>";
}
?>
I believe it is because you have this line of code:
$('#datepicker').serialize()
This should be changed to the id of the form not the datapicker. In your PHP you are trying to get two seperate values:
$treatment = $_POST['treatment'];
$bookdate = $_POST['bookdate'];
Right now you are just sending the value of the input field #datepicker.

Only get new data from PHP file - jQuery

Instead of reloading old data from a PHP file that I parse with JavaScript using JSON, I want to ONLY load new data. My project is a little multiplayer environment and my goal is to have all users see either other move in realtime.
Here is my code:
JavaScript:
function getUsers() {
$.get("database/getData.php", function(data) {
// data returned from server;
for(var i = 0; i < data.response.length; i++) {
// users obtained from the array... parse them now
var user = data.response[i].split(" ");
// user info
var id = user[0];
var username = user[1];
var xx = user[2];
var yy = user[3];
userCount = data.response.length;
$(".online").html(userCount + " users online right now.")
// position the users
moveCharacter(username, xx, yy);
}
}, "json");
}
var infoGetter = setInterval(getUsers, 2000); // we may need to improve this... type of realtime
And here is my PHP:
<?
$database = sqlite_open("thenew.db", 0999, $error);
if(!$database) die($error);
$query = "SELECT * FROM users";
$results = sqlite_query($database, $query);
if(!$results) die("Canot execute query");
$data = array();
while($row = sqlite_fetch_array($results)) {
$data[] = $row['uid'] . " " . $row['username'] . " " . $row['xPos'] . " " . $row['yPos'];
}
echo json_encode(array("response"=>$data));
sqlite_close($database);
?>
How can I make it so ONLY new data from the PHP file is parsed by the JavaScript instead of all data?
Thanks!
I would suggest you to modify the select query. Instead of having it as select * from users, add some where condition like where userId > somenumber. Now send the last userId which we processed in the last request along with next request which you make from client side. This will make sure that you will always gets new response.
Indeed, with your current setup, every call to "getUsers" will replay the entire state of the game up to the last move made, and not necessarily finish in the correct state. In order to get the behavior you want, you will need to add a timestamp or serial id to the "users" table and then order your results in order to get the most recent moves. You will need to do this for each user separately, so you will also need to provide a mechanism to retrieve and iterate through all users...
Thus your javascript becomes something like...
function getUsers() {
$.get("database/getAllUsers.php", function(data) {
$.each(data, function(i,uid) {
$.get("database/getData.php?uid=".uid, function(data) {
...
and your php query becomes...
$query = "SELECT * FROM users WHERE uid=$_GET['uid'] ORDER BY timestamp DESC LIMIT 1

Categories