Jump to content

YouTube embed help


richard_PHP

Recommended Posts

Hello all,

 

Using a database backend and the WHILE function I'm wanting all YouTube videos entered in said database to show up in one loop. Simples. However, coded it's deciding that it does not want to play ball.

 

Code:

<?php
				// Start the connection to the database
				$conn = mysql_pconnect("****", "******", "*****");
				// Select the database to use
				mysql_select_db("*****", $conn);
				// Create the MySQL command to retrieve all records
				$sql = "SELECT * FROM videos";
				$result = mysql_query($sql, $conn);
				while ($array = mysql_fetch_array($result)) {
					$title = $array[title];
					$hlink = $array[hlink];
					$desc = $array[description];
					echo "<h2>$title</h2>";
					echo "<iframe width='560' height='315' src='$hlink' frameborder='0' allowfullscreen></iframe>";
					echo "<p>$desc</p><hr />";
				}
			?>

 

The YouTube embed is in an echo line with the link to the video (eg: 'http://www.youtube.com/*****') in variable '$hlink'. I've tried \" instead of single quotes and it still isn't working.

 

Hopefully someone can help.

 

Thanks in advance  :)

Link to comment
https://forums.phpfreaks.com/topic/264121-youtube-embed-help/
Share on other sites

At first I showed this from your code.

 

$title = $array[title];

$hlink = $array[hlink];

$desc = $array[description];

 

Strings in the square brackets need to be within single quotes.

 

$title = $array['title'];
$hlink = $array['hlink'];
$desc = $array['description'];

Link to comment
https://forums.phpfreaks.com/topic/264121-youtube-embed-help/#findComment-1353542
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.