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
    }
?>
2
  • 2
    why u have a function inside a loop? can you see any javascript errors on firebug Commented Feb 24, 2013 at 6:03
  • You forgot to ask a question Commented Feb 24, 2013 at 6:37

1 Answer 1

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?

1
  • Okay that works for images but then how do I get the title of a youtube video without using javascript inside the loop? Commented Feb 24, 2013 at 6:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.