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