Hi,
I would like to check if this is normal? The following php codes
belong to videosources.php
Sorry, If i made a mistake. I am a student working on the website as
project.
The mysql database have the follow:
INSERT INTO `categories` (`id`, `name`) VALUES ('1','Dev Events');
INSERT INTO `categories` (`id`, `name`) VALUES ('2','Technology');
INSERT INTO `videos` VALUES (
NULL,
'1',
'2010 Day 1 Keynote',
'Dev Events',
'IO2010 Keynote',
'images/thumbs/thumb01.jpg',
'
http://commondatastorage.googleapis.com/gtv_template_assets/IO2010-
Keynote-day1.mp4',
now()
);
INSERT INTO `videos` VALUES (
NULL,
'2',
'Google Chrome Extensions and Accessibility',
'Technology',
'Rachel Shearer',
'images/thumbs/thumb01.jpg',
'
http://commondatastorage.googleapis.com/gtv_template_assets/Chrome-
Accessibility.mp4',
now()
);
<?php
// Copyright 2010 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
// See the License for the specific language governing permissions and
// limitations under the License.
require_once("db.php");
require_once 'Zend/Json.php';
$category_collection = array();
$videos = array();
//$q = "SELECT * FROM videos ORDER BY category_id";
$q = "SELECT * FROM videos, categories WHERE videos.category_id =
categories.id ORDER BY category_id";
$results = $db->get_results($q);
$category = array();
$category_collection = array();
$videos = array();
$catid = 1;
foreach( $results as $r ) {
if( $catid != $r->category_id ) {
// add category array
// I think something is wrong here.
$category = array("name" => $r->name, "videos" => $video);
array_push($category_collection, $category);
//reset videos array
$catid = $r->category_id;
$videos = array();
}
$i = array("sources" => array($r->video_url),
"thumb" => $r->thumbnail_url,
"title" => $r->title,
"subtitle" => $r->subtitle,
"description" => $r->description);
array_push($videos, $i);
}
// add last category array
$category = array("name" => $r->name, "videos" => $videos);
array_push($category_collection, $category);
// create categories array
$output = array("categories" => $category_collection);
// output categories array in JSON using Zend JSON encoder
echo Zend_Json::encode($output);
?>
{"categories":[{"name":"Technology","videos":null},
{"name":"Technology","videos":[{"sources":["http:\/\/
commondatastorage.googleapis.com\/gtv_template_assets\/Chrome-
Accessibility.mp4"],"thumb":"images\/thumbs\/
thumb01.jpg","title":"Google Chrome Extensions and
Accessibility","subtitle":"Technology","description":"Rachel
Shearer"}]}]}
Are we suppose to see Technology Category only? Where is the Dev
Events and its videos data?