Martin
Martin

Reputation: 615

Implementing my Javascript function to database query results

I've got my JS function

<html>
  <head>
    <script>
      function createYoutubeEmbedLink(link){
          return link.replace("http://www.youtube.com/watch?v=",
                                  "http://www.youtube.com/embed/");
        }
    </script>
  </head>

And I'm trying to get it to work with my query what I'm getting from the database

            while($songs = mysql_fetch_array($data))
        {
            Print "<b>Name (id): </b>" .$songs['id'] . "</br>";
            Print "<b>Url: </b>" .$songs['url'] . "</br>";
            Print "</br>";
        }
    ?>

This will display normal Youtube URLs but I'm trying to add the JS function to it so it would convert it to Youtube Embed video. Where should i put the JS function exactly?

Upvotes: 1

Views: 82

Answers (1)

Martin
Martin

Reputation: 615

Ok found a solution. Removed the JS totally. Used str_replace instead Print " Url: " .str_replace('youtube.com/watch?v=','http://www.youtube.com/embed/ …;, $songs['url']). "";

Upvotes: 1

Related Questions