Issue in videosources.php for gtv_template2_ajax

7 views
Skip to first unread message

Wei Qiang Lum

unread,
Jul 9, 2011, 9:25:49 AM7/9/11
to Google TV Web Resources
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?

Shawn Shen

unread,
Jul 11, 2011, 12:08:30 PM7/11/11
to Google TV Web Resources
Hi Wei,

The videosource.php file works for me. You should manually run the
following query:

SELECT * FROM videos, categories WHERE videos.category_id =
categories.id ORDER BY category_id

against your DB and double check that you get the right number of
records returned back. For example, my DB returns 56 rows:

| 55 | 6 | Campfire Part
5 | Events | CF1
AppsMarketplace Part5 | images/thumbs/thumb13.jpg |
http://commondatastorage.googleapis.com/gtv_template_assets/CF1-AppsMarketplace-Part5.mp4
| 2011-04-19 17:12:16 | 6 | Events | 2011-04-19 17:12:16 |
| 56 | 6 | Campfire Part
6 | Events | CF1
AppsMarketplace Part6 | images/thumbs/thumb14.jpg |
http://commondatastorage.googleapis.com/gtv_template_assets/CF1-AppsMarketplace-Part6.mp4
| 2011-04-19 17:12:16 | 6 | Events | 2011-04-19 17:12:16 |
+----+-------------
+----------------------------------------------------+-------------
+---------------------------+---------------------------
+---------------------------------------------------------------------------------------------
+---------------------+----+-------------+---------------------+
56 rows in set (0.00 sec)


In particular you'd expect to see all the categories you INSERTED into
your DB. If not, your DB is either corrupt or insertions didn't quite
succeed.

If you do get the right number of records, then you add some debug
print statement in your php to continue debugging. Or if you use a
json pretifier, you'll get output like mine below, where you do see
more than 1 category.

Let me know if you figure this out.

- Shawn


Array
(
[categories] => Array
(
[0] => Array
(
[name] => Technology
[videos] => Array
(
[0] => Array
(
[sources] => Array
(
[0] =>
http://commondatastorage.googleapis.com/gtv_template_assets/CF1-AppsMarketplace-Part5.mp4
)

[thumb] => images/thumbs/
thumb13.jpg
[title] => Campfire Part 5
[subtitle] => Dev Events
[description] => CF1
AppsMarketplace Part5
)

[1] => Array
(
[sources] => Array
(
[0] =>
http://commondatastorage.googleapis.com/gtv_template_assets/CF1-AppsMarketplace-Part6.mp4
)

[thumb] => images/thumbs/
thumb14.jpg
[title] => Campfire Part 6
[subtitle] => Dev Events
[description] => CF1
AppsMarketplace Part6
)
......
)

)

[1] => Array
(
[name] => Conferences
[videos] => Array
(
[0] => Array
(
[sources] => Array
(
[0] =>
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
)
> <?php// Copyright 2010 Google Inc. All Rights Reserved.

Matthew Wedeking

unread,
Jan 13, 2012, 11:04:44 PM1/13/12
to google-tv-w...@googlegroups.com
Hi Wei,

What I had to do was:

...
foreach( $results as $r ) { 
    if( $catid != $r->category_id ) { 
        // add category array 
       // I think something is wrong here. 
        $category = array("name" => $genre, "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); 
   
   $genre = $r->name

...

If not you miss the first category and the videos are under the wrong ones (in the next category)

matt
Reply all
Reply to author
Forward
0 new messages