JSON code for my radio station website? - php

This is part of my radio station website's PHP coding:
http://pastebin.com/D1TUMNSc
I've got the PHP to work; but getting the JSON to work is a problem, I'm not sure how to do it with the variables I've got...
Currently the schedule page shows as blank, since I'm not sure what to do.
The Javascript is here: http://pastebin.com/P1ydnVCK
Basically, I'm having trouble trying to create a JSON to fit within the variables of the Javascript, it's new to me, this area of programming...
What would you suggest?
I've had a look around the net at JSON resources but am not quite sure what to do for this one!

Just a quick look so this may not be everything you need, but.... You need to do something like this....
$json->schedule = array();
// Loop Here
$show = array(
'longname' => 'xxxxx',
'description' => 'xxxxxx',
'weblink' => 'http://xxxx.com',
'showimage' => 'xxxx',
'startminutes' => '0000000',
'endminutes' => '000000',
);
// End Loop
$json->schedule[] = $show;
echo json_encode($json);
In your javascript anything prefixed with _s needs to be a variable... Ex: this._s.longname

Related

php array to call wordpress get_current_user_info

I've been reading and tweaking code for three days and can't figure this out. Because I'm new to php. The developer that wrote this php login script didn't code it for WordPress and not for an automatic login like I need. I think I've figured out the automatic login at the end of the code I didn't post here.
He created this code for his array that will have set values for the three api strings that never change, but I need to include the logged in WordPress user's username and password to be included in his array. The array info is passed by xml later in the script. This is for an automated SSL login to another server and when an image is clicked it runs the php code.
This is the code I just got from him, but I don't believe it's correct because all of the colors just changed in Notepad++ when I inserted it:
// Set the Query POST parameters - array
$query_vals = array(
'api_username' => 'api-username-goes-here',
'api_password' => 'password-here',
'api_key' => 'api-key-here’,
'username' => $current_user[‘user_login’],
'password' => $current_user[‘user_pass’]
);
I know the last two lines can't be correct. What's the correct code to access the WordPress get user variables to use with his array?
Any help is greatly appreciated.
Change ‘ to '
// Set the Query POST parameters
$query_vals = array(
'api_username' => 'api-username-goes-here',
'api_password' => 'password-here',
'api_key' => 'api-key-here',
'username' => $current_user['user_login'],
'password' => $current_user['user_pass']
);
You need to call this somewhere in your code first:
global $current_user;
get_currentuserinfo();
Then you'll want to change your array to stuff like this:
'username' => $current_user->user_login

Simultaneously insert data into same table with PHP (laravel)

I'm not sure if this is even possible but what the heck :) I have two URL, both trying to insert different data into the same table. Example
We have table "food" and two URL with functionality that insert into FOOD table some values
http://example.com/insert_food_1
http://example.com/insert_food_2
When loading both URLs in the same time, every one of them waits for the other one to finish first and afterwards inserts into the DB the specific values.
I know this is called multithreading or something... but i'm not sure if this can be done with PHP (or Laravel).
Any help would be much appreciated. My code looks like so ...
$postToInsert = Post::create(
array(
'service_id' => 1,
'custom_id' => $post->body->items[0]->id,
'url' => $post->body->items[0]->share_url,
'title' => $post->body->items[0]->title,
'title_tags' => $tags,
'media_type' => $mediaType,
'image_url' => $imageURL,
'video_url' => $videoURL
));
$postToInsert->save();
I kind of fix it. Opening them in separate browsers or php them via CURL from terminal solves the problem.
Thanks for all the help

Three JSON strings in one AJAX request conflicting in Zend

I have three different request for my ajax:
$result = Map_Model_Map_Factory::getCityByRegionAlias($alias);
$resultCountUsers = User_Model_User_Factory::countUserByRegion($alias);
$resultCountPartners = User_Model_User_Factory::countPartnersByRegion($alias);
First request works pretty well. But second and third conflicts with each other. If $this->_helper->json($resultCountUsers); comes first, then it works:
$this->_helper->json($resultCountUsers);
$this->_helper->json($resultCountPartners);
$this->_helper->json($result);
I get what I need countUsers: "1" but I don't have countPartners. And vice versa, if $this->_helper->json($resultCountPartners); comes first, then I get countPartners without countUsers.
Maybe somebody know, what's going on and how I can receive that.
I don't use Zend, but there is clearly a problem: you are not providing attribute names for the JavaScript object. I wonder whether you are overwriting each response with the next one.
See what effect this has in your AJAX viewer:
$this->_helper->json(
array(
'resultCountUsers' => $resultCountUsers,
'resultCountPartners' => $resultCountPartners,
'result' => $result,
)
);

jquery gantt plugin

Situation
I'm using a jQuery gantt plugin from here and integrating it with a PHP site I have. In terms of setting up the demo there are no problems; however when I try to feed the plugin some of my own data, it will throw up the following error:
TypeError: e is undefined
Now, I believe the above error is thrown due to the JSON object being unfamiliar to the plugin but, I just can't seem to package it correctly.
My JSON Data
Demo JSON Data
Now, you can see other than a few differences, I am pretty close to the mark. Up next is the PHP code I use to generate this.
$aryOutput = array('source' => array());
if($aryTasks) {
foreach($aryTasks as $aryTask) {
$aryOutput['source'][] = array(
'name' => $aryTask['task_stage'],
'desc' => $aryTask['task_title'],
'values' => array(array(
'to' => '/Date('.time($aryTask['task_projected_end_timestamp']).')',
'from' => '/Date('.time($aryTask['task_projected_start_timestamp']).')',
'desc' => $aryTask['task_description'],
'label' => $aryTask['task_description']
))
);
}
}
$strJSON = json_encode($aryOutput, JSON_UNESCAPED_SLASHES);
Please can anyone offer some pearls of wisdom to resolve this matter. On a side note, from another question, I saw that the class has to be gantt. This is not a problem, I can get the plugin working with a different data set.
Thank you
Edit
I noticed a small difference with the date field having an extra slash on it. After editing the code to add it, the error still occurs
Check the complete delivered JSON is structure as needs be. In the above example, it is likely this is the output:
source : { source : { ... } }
This causes confusion with the plugin as it is unexpected data.

How do I get FullCalendar to display information from my JSON feed?

I'm setting up an app using FullCalendar (http://arshaw.com/fullcalendar/) that will allow the user to see client scheduling information as well as schedule clients through a management interface.
I want to use a MySQL database to populate an array, and then pass that array in the form of a JSON feed to FullCalendar on an HTML page. Ideally, then, the client information would show up on the HTML page. However, even though my JSON feed is being passed, there are no events on my FullCalendar.
Example JSON feed being passed:
[{"title":"Watson","start":"1333976400","end":"1333980000","allDay":false}]
I'm fairly new to these languages and I would not be surprised if this mistake turn out to be simple.
I would deeply appreciate any help or insight on having these events show up. When I manually feed an array into FullCalendar, it does show the events, but so far my JSON feed has resulted in no information being displayed.
Thank you
For reference:
HTML:
$(document).ready(function() {
$('#calendar').fullCalendar({
events: '/json-events.php'
});
});
PHP:
while ($record = mysql_fetch_array($result)) {
$event_array[] = array(
'id' => $record['id'],
'title' => $record['title'],
'start' => $record['start_date'],
'end' => $record['end_date'],
'allDay' => false
);
}
echo json_encode($event_array);
So the problem, for those searchers that come after me, was that my PHP file had HTML head and body tags. I'm a PHP noob and so I didn't know that would cause it not to work. In order for FullCalendar to display the JSON feed, it must ONLY have PHP code, no HTML. JSONLint.com was invaluable in figuring that out.
I set up a quick example and didn't have any trouble getting this to work:
PHP:
<?php
$record[0]["title"]="Test 1";
$record[1]["title"]="Test 2";
$record[2]["title"]="Test 3";
$record[0]["start_date"]="1333976400";
$record[1]["start_date"]="1333976401";
$record[2]["start_date"]="1333976402";
$record[0]["end_date"]="1333980000";
$record[1]["end_date"]="1333980001";
$record[2]["end_date"]="1333980002";
$record[0]["id"]="1";
$record[1]["id"]="2";
$record[2]["id"]="3";
for ($i=0; $i<3; $i++) {
$event_array[] = array(
'id' => $record[$i]['id'],
'title' => $record[$i]['title'],
'start' => $record[$i]['start_date'],
'end' => $record[$i]['end_date'],
'allDay' => false
);
}
echo json_encode($event_array);
exit;
?>
HTML:
events: '/events.php'
Sample output from the PHP script:
[{"id":"1","title":"Test 1","start":"1333976400","end":"1333980000","allDay":false},{"id":"2","title":"Test 2","start":"1333976401","end":"1333980001","allDay":false},{"id":"3","title":"Test 3","start":"1333976402","end":"1333980002","allDay":false}]
So given that the above works for me and it's really no different to what you have above, you might need to check that the PHP script is actually getting called correctly. Check the Javascript console in Mozilla Firefox or Google Chrome to see if there are any errors thrown when Fullcalendar tries to load the events. Check your web server access/error logs for any mention of the PHP script.
events: '/json-events.php'
should be either
events: './json-events.php'
or
events: 'json-events.php'
Let me know if this helps...
EDIT
I also noticed that in the Json that your are receiving there is no id in the line. There may be something going on between the nameing of you id within the DB comparitively to the name your using in the array. Check it out and see if that is what is going on, because that is one of the properties that are required to pass the event.
EDIT
Try removing the [] from $event_array[] and see what happens... If that doesn't work than I am stumpped... sorry

Categories