Jump to content

Javascript & Php?


Ptsface12

Recommended Posts

Hello,

I'm currently working on a gaming website, however there is an issue. I have a custom YouTube player, however I need to get the link dependant on a value from the database. The ID is in the URL, which is then collecting the youtube video URL from the database. However, I'm trying to then echo that back out into the Javascript video.

 

On my normal page, that plays the Video is:

 

Header: Styles.css & youTubeEmbed-jquery-1.0.css need to be added.

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Having Fun With YouTube's API - Making a Custom Video Player | Tutorialzine Demo</title>

<link rel="stylesheet" type="text/css" href="styles.css" />
<link rel="stylesheet" type="text/css" href="video_player/youTubeEmbed/youTubeEmbed-jquery-1.0.css" />

</head>

 

Footer: All of that needs to be added.


<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="jquery.swfobject.1-1-1.min.js"></script>
<script src="youTubeEmbed/youTubeEmbed-jquery-1.0.js"></script>
<script type="text/javascript">
$(document).ready(function(){

$('#player').youTubeEmbed("VID LINK FROM DB SHOULD BE HERE");


$('form').submit(function(){
	$('#player').youTubeEmbed({
    video           : 'VID LINK FROM DB SHOULD BE HERE',
    width           : 640,      // Height is calculated automatically
    progressBar : false     // Hide the progress bar
});
});




});



</script>

</body>
</html>

 

 

<?php

include("config.php");

$host = $config['Site']['Host'];
$username = $config['Site']['Username']; 
$password = $config['Site']['Password']; 
$database = $config['Site']['Database'];
$name = $config['Site']['Name'];
$favicon = $config['Site']['Favicon'];

mysql_connect($host, $username, $password) or die(mysql_error());
mysql_select_db($database) or die(mysql_error());

function getVid() {
$vID = $_GET['vID'];

$sQuery = "SELECT * FROM vids WHERE id='$vID'";
$sResult = mysql_query($sQuery);

while($row = mysql_fetch_array($sResult)) {
$vID = $row['url'];
   }
}

?>

 

Above is the Global.php, and that's where the problem lies, whenever I try to insert the peices required, nothing happens and the video doesn't show. Could anybody please help?!

Link to comment
Share on other sites

Indeed I do, but it doesn't work, however I will insert what I have so far. (Not working!)

 

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="styles.css" />
<link rel="stylesheet" type="text/css" href="video_player/youTubeEmbed/youTubeEmbed-jquery-1.0.css" />

</head>
<?php

include("config.php");

$host = $config['Site']['Host'];
$username = $config['Site']['Username']; 
$password = $config['Site']['Password']; 
$database = $config['Site']['Database'];
$name = $config['Site']['Name'];
$favicon = $config['Site']['Favicon'];

mysql_connect($host, $username, $password) or die(mysql_error());
mysql_select_db($database) or die(mysql_error());

function getVid() {
$vID = $_GET['vID'];

$sQuery = "SELECT * FROM vids WHERE id='$vID'";
$sResult = mysql_query($sQuery);

while($row = mysql_fetch_array($sResult)) {
global $vName, $vURL, $vDesc;
$vURL = $row['url'];
$vName = $row['title'];
$vDesc = $row['description'];


   }

}



?>
<div id=\"player\" align=\"center\">

</div>


</body>


<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="jquery.swfobject.1-1-1.min.js"></script>
<script src="youTubeEmbed/youTubeEmbed-jquery-1.0.js"></script>
<script type="text/javascript">
$(document).ready(function(){

$('#player').youTubeEmbed("http://www.youtube.com/watch?v=P1HGQQxmnP4");


$('form').submit(function(){
	$('#player').youTubeEmbed({
    video           : 'http://www.youtube.com/watch?v=P1HGQQxmnP4',
    width           : 640,      // Height is calculated automatically
    progressBar : false     // Hide the progress bar
});
});




});



</script>

</body>
</html>

 

Here are the instructions given by the document with the flash player:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Having Fun With YouTube's API - Making a Custom Video Player | Tutorialzine Demo</title>

<link rel="stylesheet" type="text/css" href="styles.css" />
<link rel="stylesheet" type="text/css" href="youTubeEmbed/youTubeEmbed-jquery-1.0.css" />

</head>

<body>

<h1>Making a Custom YouTube Video Player</h1>
<h2><a href="http://tutorialzine.com/2010/07/youtube-api-custom-player-jquery-css/">Back to Tutorialzine »</a></h2>

<div id="page">

<p>This is a demo for Tutorialzine's Youtube API tutorial, in which we show you how to use YouTube's APIs, to create a custom CSS player for YouTube videos in a form of a jQuery plugin. Embedding videos in your website has never been easier. Just run the following code:</p>

<pre>$('#element').youTubeEmbed('http://www.youtube.com/watch?v=u1zgFlCw8Aw');

// Or:

$('#element').youTubeEmbed({
video			: 'http://www.youtube.com/watch?v=u1zgFlCw8Aw',
width			: 600, 		// Height is calculated automatically
progressBar	: false		// Hide the progress bar
});
</pre>

<p>The plugin uses YouTube's chromeless player, which allows you to build your own player controls. Changing the play/pause buttons or the progress bar is as easy as changing a couple of CSS values.</p>
    
    <blockquote>
    <p>To test the plugin, fill in a YouTube Video URL in the textbox below and hit "Embed".</p>
    <form action="">
        <fieldset>
        	<input type="text" id="url" />
            <input type="submit" id="submitButton" value="Embed" />
            <small>(if embedding has been disabled on the video, it will not show up)</small>
        </fieldset>
    </form>
</blockquote>
<div id="player"></div>

</div>


<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="jquery.swfobject.1-1-1.min.js"></script>
<script src="youTubeEmbed/youTubeEmbed-jquery-1.0.js"></script>
<script src="script.js"></script>

</body>
</html>

 

(Script JS is the <script type="text/javascript"> at the bottom!)

 

Thanks!

Link to comment
Share on other sites

Again, I don't see you using echo anywhere in your code.

 

On another note, you should avoid using the global keyword.

http://tjhunt.blogspot.com/2009/04/php-global-variables-are-not.html

 

On another note, what happens when page.php?vID=' OR 1=1 is called?

 

On another note, why do you declare the funtion 'getVid' ? It has no reusable code, and isn't ever called itself?

Link to comment
Share on other sites

Age has nothing to do with this.

 

You're trying to use the language, not learn it. There are plenty of introductory tutorials on the web that will help you. Maybe get your parent's to grab you a good PHP book for whichever winter gift-giving event you celebrate.

 

At this point, you're asking us to tell you what value to use without giving us any values. We simply know what you want to do, and that the data you need is stored in a MySQL database with at least 3 columns.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.