So I have a place on my site where members submit their youtube videos. I basically just write the full youtube URL of the video into a table in the database. Tonight I was playing around trying to read the urls from the database and embed them into an html page with tables (yes tables are lame and will be changed to DIVs once I get this working).

It all seems to work, BUT the video doesn’t display and if you right-click the area it says "movie not loaded"


Can anybody see what i missed in my code?

<html><head><title>videos</title></head>
<?php
$db_host = 'localhost';
$db_user = 'username';
$db_pwd = 'password';
$database = 'db';
$table = 'tablename';
if (!mysql_connect($db_host, $db_user, $db_pwd))
    die("Can't connect to database");
if (!mysql_select_db($database))
    die("Can't select database");
$result = mysql_query("SELECT video_url FROM tablename");
if (!$result) {
    die("Query to show fields from table failed");
}
$fields_num = mysql_num_fields($result);
echo "<h1>Videos:</h1>";
echo "<table border='1'><tr>";
for($i=0; $i<$fields_num; $i++)
{
    $field = mysql_fetch_field($result);
    echo "<td>{$field->name}</td>";
}
echo "</tr>n";
while($row = mysql_fetch_row($result))
{
    echo "<tr>";
    foreach($row as $cell)
		$videoWidth = '320';
		$videoHeight = '240';
        $embed = '<object width="' . $videoWidth . '" height="' . $videoHeight . '">'.
                 '<param name="movie" value="'. $cell . '"></param>'.
                 '<param name="allowFullScreen" value="true"></param>'.
                 '<param name="allowscriptaccess" value="always"></param>'.
                 '<embed src="' . $cell. '" type="application/x-shockwave-flash" '.
                 'allowscriptaccess="always" allowfullscreen="true" '.
                 'width="' . $videoWidth . '" height="' . $videoHeight . '"></embed></object>';
		echo "<td>" . $embed . "</td>";
    echo "</tr>n";
}
mysql_free_result($result);
?>
</body></html>

Can you post the source generated by that page? Perhaps the embbed code is missing something?

<html><head><title>MySQL Table Viewer</title></head>
<h1>Table: xmb_video</h1><table border='1'><tr><td>videourl</td></tr> 
<tr><td><object width="320" height="240"><param name="movie" value="http://www.youtube.com/watch?v=r18AWC4j-EE"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/watch?v=r18AWC4j-EE" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="320" height="240"></embed></object></td></tr> 
<tr><td><object width="320" height="240"><param name="movie" value="http://www.youtube.com/watch?v=1CKwYlc-q88"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/watch?v=1CKwYlc-q88" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="320" height="240"></embed></object></td></tr>
</table>
</body></html>

When i go to one of those videos and click the embed src button it gives me this code:

<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/r18AWC4j-EE?fs=1&hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/r18AWC4j-EE?fs=1&hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed>

The url is different than the one you have. I havent really dealt with youtube embedded stuff outside of just copying what they have there :shrug: I embeded the videos on a test html page and they show up fine. I replaced your links in with the one from above and the video showed up. The link you get from youtube is a webpage with their video embedded on it. You might need the parameters that are after the link ("?fs=1&hl=en_US"). Looking at the 2 links, they both have that behind them. Might just be a deal of just appending " ?fs=1&hl=en_US" to the end of your link code they submit. See Below.

$embed = '<object width="' . $videoWidth . '" height="' . $videoHeight . '">'.
                 '<param name="movie" value="'. $cell . '?fs=1&hl=en_US"></param>'.
                 '<param name="allowFullScreen" value="true"></param>'.
                 '<param name="allowscriptaccess" value="always"></param>'.
                 '<embed src="' . $cell. '?fs=1&hl=en_US" type="application/x-shockwave-flash" '.
                 'allowscriptaccess="always" allowfullscreen="true" '.
                 'width="' . $videoWidth . '" height="' . $videoHeight . '"></embed></object>';

give that a shot

When i go to one of those videos and click the embed src button it gives me this code:

<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/r18AWC4j-EE?fs=1&hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/r18AWC4j-EE?fs=1&hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed>

The url is different than the one you have. I havent really dealt with youtube embedded stuff outside of just copying what they have there :shrug: I embeded the videos on a test html page and they show up fine. I replaced your links in with the one from above and the video showed up. The link you get from youtube is a webpage with their video embedded on it. You might need the parameters that are after the link ("?fs=1&hl=en_US"). Looking at the 2 links, they both have that behind them. Might just be a deal of just appending " ?fs=1&hl=en_US" to the end of your link code they submit. See Below.

$embed = '<object width="' . $videoWidth . '" height="' . $videoHeight . '">'.
                 '<param name="movie" value="'. $cell . '?fs=1&hl=en_US"></param>'.
                 '<param name="allowFullScreen" value="true"></param>'.
                 '<param name="allowscriptaccess" value="always"></param>'.
                 '<embed src="' . $cell. '?fs=1&hl=en_US" type="application/x-shockwave-flash" '.
                 'allowscriptaccess="always" allowfullscreen="true" '.
                 'width="' . $videoWidth . '" height="' . $videoHeight . '"></embed></object>';

give that a shot

fuck…you’re right!!!!

i should’ve remembered that because I fought with that shit previously

EDIT: N/M that didn’t work…

What’s the output of the page when you added the ?fs=1&hl=en_US to the end of the link?

<html><head><title>MySQL Table Viewer</title></head><body> 
<h1>Table: xmb_video</h1><table border='1'><tr><td>videourl</td></tr> 
<tr><td><object width="320" height="240"><param name="movie" value="http://www.youtube.com/watch?v=r18AWC4j-EE?fs=1&hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/watch?v=r18AWC4j-EE?fs=1&hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="320" height="240"></embed></object></td></tr> 
</table></body></html>

Does changing & to & fix it?

I just noticed a difference in the 2 links.

The Database Link:

The Embeded Link:

There are a few ways you can tackle this.

1. Have your users submit the embeded link from Youtube. This would give you the exact Link. Not quite user friendly, but would work. This would work with your current code.
2. Have them submit the video number that comes after the v= in the address (i.e. r18AWC4j-EE). This would be ideal, easy to get for the user and you can just use the number to pull and insert into the embeded link in your code. [ideal]

$embed = '<object width="' . $videoWidth . '" height="' . $videoHeight . '">'.
                 '<param name="movie" value="'. $cell . '?fs=1&hl=en_US"></param>'.
                 '<param name="allowFullScreen" value="true"></param>'.
                 '<param name="allowscriptaccess" value="always"></param>'.
                 '<embed src="http://www.youtube.com/v/' . $cell.  '?fs=1&hl=en_US" type="application/x-shockwave-flash" '.
                 'allowscriptaccess="always" allowfullscreen="true" '.
                 'width="' . $videoWidth . '" height="' . $videoHeight . '"></embed></object>';

3. Take what they submitted ripout what comes after the v= on the link and drop that into a new link. This is just a cheesy way to do it. It just finds the position of v= and gets everything after it(which would work unless there’s more crap behind it). Now this could be updated a little to look through the string and grab everything after the v= and stop when it gets to a "&" or "&". That could work.

//Find Position of 'v='
$pos = strpos($cell, "v=");
//Pull just Video Number
$cell = substr($cell, $pos, strlen($cell)-$pos); 
$embed = '<object width="' . $videoWidth . '" height="' . $videoHeight . '">'.
                 '<param name="movie" value="'. $cell . '?fs=1&hl=en_US"></param>'.
                 '<param name="allowFullScreen" value="true"></param>'.
                 '<param name="allowscriptaccess" value="always"></param>'.
                 '<embed src="' . $cell. '?fs=1&hl=en_US" type="application/x-shockwave-flash" '.
                 'allowscriptaccess="always" allowfullscreen="true" '.
                 'width="' . $videoWidth . '" height="' . $videoHeight . '"></embed></object>';

I’d probably get the users to just submit the video number.

Sorry for the delayed reply. at work trying not to work I tested the last one with the links you had and it works, but it probably needs some work.

no prob… thanks for taking a look at it. it may also be fucking up because its querying about 400 videos

Ok this should work. This will take your current youtube links and strip out just the video number and put it in the link so it can be embedded.

// Find the Position of 'v='
$pos = strpos($cell, "v=");
//Grab everything from 'v=' to the end of the string
$cell = substr($cell, $pos, strlen($cell)-$pos);
$qpos = 0;
// get position of '&' 
$qpos = strpos($cell, "&");
if ($qpos != 0) {
// if '&' exists in the string, drop it and everything after it
$cell = substr($cell, 0, $qpos);
}
// Remove the 'v=' from string
$cell = substr($cell, 2, strlen($cell)-2);
// Return the new value for $cell which is full embedded Youtube link.
$cell = "http://www.youtube.com/v/".$cell."?fs=1&hl=en_US";
$embed = '<object width="' . $videoWidth . '" height="' . $videoHeight . '">'.
                 '<param name="movie" value="'. $cell . '"></param>'.
                 '<param name="allowFullScreen" value="true"></param>'.
                 '<param name="allowscriptaccess" value="always"></param>'.
                 '<embed src="' . $cell. '" type="application/x-shockwave-flash" '.
                 'allowscriptaccess="always" allowfullscreen="true" '.
                 'width="' . $videoWidth . '" height="' . $videoHeight . '"></embed></object>';

Let me know.

Ok this should work. This will take your current youtube links and strip out just the video number and put it in the link so it can be embedded.

// Find the Position of 'v='
$pos = strpos($cell, "v=");
//Grab everything from 'v=' to the end of the string
$cell = substr($cell, $pos, strlen($cell)-$pos);
$qpos = 0;
// get position of '&' 
$qpos = strpos($cell, "&");
if ($qpos != 0) {
// if '&' exists in the string, drop it and everything after it
$cell = substr($cell, 0, $qpos);
}
// Remove the 'v=' from string
$cell = substr($cell, 2, strlen($cell)-2);
// Return the new value for $cell which is full embedded Youtube link.
$cell = "http://www.youtube.com/v/".$cell."?fs=1&hl=en_US";
$embed = '<object width="' . $videoWidth . '" height="' . $videoHeight . '">'.
                 '<param name="movie" value="'. $cell . '"></param>'.
                 '<param name="allowFullScreen" value="true"></param>'.
                 '<param name="allowscriptaccess" value="always"></param>'.
                 '<embed src="' . $cell. '" type="application/x-shockwave-flash" '.
                 'allowscriptaccess="always" allowfullscreen="true" '.
                 'width="' . $videoWidth . '" height="' . $videoHeight . '"></embed></object>';

Let me know.

it worked!!!

now my next step is to split them into rows of 3 on the page instead of one column

You could add a counter and have it count from 0 to 2 (3 columns). When the counter is 0, it drops a <tr> in teh code. Then it drops the <td> data</td> until the counter gets to 2, then it drops the </tr> to close the row.
Something like this (i have not tested this though )

<html><head><title>videos</title></head>
<?php
$db_host = 'localhost';
$db_user = 'username';
$db_pwd = 'password';
$database = 'db';
$table = 'tablename';
if (!mysql_connect($db_host, $db_user, $db_pwd))
    die("Can't connect to database");
if (!mysql_select_db($database))
    die("Can't select database");
$result = mysql_query("SELECT video_url FROM tablename");
if (!$result) {
    die("Query to show fields from table failed");
}
$fields_num = mysql_num_fields($result);
echo "<h1>Videos:</h1>";
echo "<table border='1'><tr>";
for($i=0; $i<$fields_num; $i++)
{
    $field = mysql_fetch_field($result);
    echo "<td>{$field->name}</td>";
}
echo "</tr>n";
// Add a counter
$counter = 0;
while($row = mysql_fetch_row($result))
{
//CHeck if counter is 0
If $counter == 0 {
      echo "<tr>";
}
    foreach($row as $cell)
        $videoWidth = '320';
        $videoHeight = '240';
        $embed = '<object width="' . $videoWidth . '" height="' . $videoHeight . '">'.
                 '<param name="movie" value="'. $cell . '"></param>'.
                 '<param name="allowFullScreen" value="true"></param>'.
                 '<param name="allowscriptaccess" value="always"></param>'.
                 '<embed src="' . $cell. '" type="application/x-shockwave-flash" '.
                 'allowscriptaccess="always" allowfullscreen="true" '.
                 'width="' . $videoWidth . '" height="' . $videoHeight . '"></embed></object>';
        echo "<td>" . $embed . "</td>";
// Add one to the counter
$counter++;
//Check if counter is 2 (third column)
if $counter == 2 {
      echo "</tr>n";
$counter = 0;
}
}
mysql_free_result($result);
?>
</body></html>

You could add a counter and have it count from 0 to 2 (3 columns). When the counter is 0, it drops a <tr> in teh code. Then it drops the <td> data</td> until the counter gets to 2, then it drops the </tr> to close the row.
Something like this (i have not tested this though )

ya, I actually worked on something similar earlier and got it working. Then I jumped into pagination and have been fucking with that for 3 hours

Found a tutorial pagination class.php to walk through and got it working, but the videos stopped showing up which I narrowed down to being a class function being used in the query, but I’m over it for tonight!

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© 2013 Tag ORDA - Webmaster Lab Suffusion theme by Sayontan Sinha