0

So I'm trying to display the title and thumbnail of a youtube video based on the video id's which are stored in an SQL database by getting the innerHTML of a div id and changing it to the said vales. Only it doesn't do that. Here's my code:

<title>Web Editor</title>
<script>
    var vidtitle = new Array();
    var vidthumb = new Array();
    window.onload=function(){
    }
</script>
<?php
    mysql_connect("$host","$username","$pass");
    mysql_select_db("$db");
    $vidid;
    $result=mysql_query("SELECT * FROM ids");
    while($row=mysql_fetch_array($result))
    {
        $recid=$row['id'];
?>
<div id='video<?php echo $recid; ?>'>Loading..</div>
<script>
    document.getElementById("video<?php echo $recid; ?>").innerHTML=<?php echo $recid; ?>;
    var s<?php echo $recid; ?> = '';
    var k<?php echo $recid; ?> = '';
    var d <?php echo $recid; ?>='';
    function youtubeFeedCallback(data) {
        s<?php echo $recid; ?> = data.entry.title.$t;
        k<?php echo $recid; ?> = data.entry.media$group.media$thumbnail[2].url;
        d<?php echo $recid; ?> = data.entry.media$group.media$description.$t.replace();
        vidtitle[1]=s<?php echo $recid; ?>
        vidthumb[1]=k<?php echo $recid; ?>
    }
</script>
<script type='text/javascript' src='http://gdata.youtube.com/feeds/api/videos/<?php echo $recid; ?>?v=2&amp;alt=json-in-script&amp;callback=youtubeFeedCallback' >
</script>
<?php
    }
?>
Cluster
  • 5,457
  • 1
  • 25
  • 36

1 Answers1

0

why you're placing the javascript function inside loop the function. to create thumbnail you can try something like this

<img src="http://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg" />

How do I get a YouTube video thumbnail from the YouTube API?

Community
  • 1
  • 1
Crazy Chuck
  • 545
  • 1
  • 7
  • 19