Jump to content


Photo

You Tube Chapter 12


  • Please log in to reply
2 replies to this topic

#1 mikel1

mikel1

    New Member

  • Members
  • Pip
  • 7 posts

Posted 28 May 2012 - 09:02 AM

Been struggling with this for a while now. The thumbs and videos are pulling in fine. What I am trying to do is pull 28 thumbs and have them in 4 rows of 7. Right now they are blowing off the page.

Attached File  youtube.php   2KB   79 downloads


<?php
define('YOUTUBE_URL', 'http://gdata.youtube.../dog/funny/bad/');
define('NUM_VIDEOS', 28);
define('NUM_VIDEOS_ROW', 7);

// Read the XML data into an object
$xml = simplexml_load_file(YOUTUBE_URL);

$num_videos_found = count($xml->entry);
if ($num_videos_found > 0) {
echo '<table><tr>';
for ($i = 0; $i < min($num_videos_found, NUM_VIDEOS, NUM_VIDEOS_ROW); $i++) {

if(($i+1)%NUM_VIDEOS_ROW === 7) {

echo '<br/>';
}
// Get the title


$entry = $xml->entry[$i];
$media = $entry->children('http://search.yahoo.com/mrss/');
$title = $media->group->title;
// Get the duration in minutes and seconds, and then format it
$yt = $media->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->duration->attributes();
$length_min = floor($attrs['seconds'] / 60);
$length_sec = $attrs['seconds'] % 60;
$length_formatted = $length_min . (($length_min != 1) ? ' minutes, ':' minute, ') .
$length_sec . (($length_sec != 1) ? ' seconds':' second');

// Get the video URL
$attrs = $media->group->player->attributes();
$video_url = $attrs['url'];

// Get the thumbnail image URL
$attrs = $media->group->thumbnail[0]->attributes();
$thumbnail_url = $attrs['url'];

// Display the results for this entry
echo '<td style="vertical-align:bottom; text-align:center" width="' . (100 / NUM_VIDEOS) . '%"><a href="' . $video_url . '" target="_blank">' .
$title . '<br /><span style="font-size:smaller; color:black">' . $length_formatted . '</span><br /><img src="' . $thumbnail_url . '" style = "width:200px; border=0" /></a></td>';
}
echo '</tr></table>';
}

else {
echo '<p>Sorry, no videos were found.</p>';
}
echo '</div>';

//echo '</div><br style="clear: both;" />';
?>

Edited by mikel1, 28 May 2012 - 09:04 AM.


#2 mikel1

mikel1

    New Member

  • Members
  • Pip
  • 7 posts

Posted 28 May 2012 - 09:18 AM

Ask yourself: For what value(s) of '$i' is this statement true?
(($i+1)%NUM_VIDEOS_ROW === 7)



#3 mikel1

mikel1

    New Member

  • Members
  • Pip
  • 7 posts

Posted 28 May 2012 - 09:24 AM

Thank you, I am back at it.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users