 |
|
07-04-2009, 12:20 AM
|
|
#1
|
 |
|
Novice (Level 1)
Join Date: Jun 2009
Posts: 6
|
Random Generated Video
Essentially what I want is to have a basic html page with one <div> tag.
Inside the <div> I'm going to have an embedded video from youtube. Except every time you load the page, a random video is selected from a predetermined list.
I thought I would just make a simple <div> tag.
<div id="example">
<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/x88h6akv8mQ&hl=en&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/x88h6akv8mQ&hl=en&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>
</div>
Then link it to the CSS
#example {
width:425px;
height:344px;
position:absolute;
}
But I'm not sure where to add extra code that would select a random video if I listed a couple dozen videos in the CSS.
Sorry if I'm not very clear, I'm new to CSS.
|
|
Add to del.icio.us
Can you digg it?
|
|
|
07-04-2009, 01:05 AM
|
|
#2
|
 |
|
Lord (Level 16)
Join Date: Nov 2007
Location: Chicago, IL. USA
Posts: 546
|
You can't add the random code just using CSS, the best way to do it is to use a server side programming language like php. In php, you could save the code for each individual youtube video as a separate string, and then you could have it echo a random string to the browser each time the page is loaded.
|
|
Add to del.icio.us
Can you digg it?
|
|
|
07-04-2009, 07:27 AM
|
|
#3
|
 |
|
Paladin (Level 15)
Join Date: Aug 2005
Location: Formby, UK
Posts: 394
|
Hi,
Another option would be to store the links in a database and use a query to echo a random video. Here is an example for you:
Database Table
Code:
CREATE TABLE `arcadianrock` (
`vID` int(5) NOT NULL auto_increment,
`videolink` varchar(200) NOT NULL,
PRIMARY KEY (`vID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
--
-- Dumping data for table `arcadianrock`
--
INSERT INTO `arcadianrock` (`vID`, `videolink`) VALUES
(1, 'http://www.youtube.com/v/rMNNDINCFHg&hl=en&fs=1&'),
(2, 'http://www.youtube.com/v/bDF6DVzKFFg&hl=en&fs=1&');
index.php
PHP Code:
<?php
$dbHost = "localhost";
$dbUser = "username";
$dbPass = "password";
$dbname = "htmlforums";
$db = mysql_connect($dbHost,$dbUser,$dbPass);
mysql_select_db($dbname,$db);
$sql = mysql_query("SELECT * FROM arcadianrock ORDER BY RAND() LIMIT 1");
$row = mysql_fetch_array($sql);
?>
<html>
<head>
<title>Random YouTube Video</title>
<style type="text/css">
#example {
width:425px;
height:344px;
position:absolute;
}
</style>
</head>
<body>
<div id="example">
<object width="425" height="344">
<param name="movie" value="<?php echo $row['videolink']; ?>"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src="<?php echo $row['videolink']; ?>" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344">
</embed></object>
</div>
</body>
</html>
|
|
Add to del.icio.us
Can you digg it?
|
|
|
07-04-2009, 07:36 AM
|
|
#4
|
 |
|
Paladin (Level 15)
Join Date: Aug 2005
Location: Formby, UK
Posts: 394
|
Another option would be to store the links in an array and randomly select one to play. See the following example:
PHP Code:
<?php
$video_array = array
('http://www.youtube.com/v/rMNNDINCFHg&hl=en&fs=1&',
'http://www.youtube.com/v/bDF6DVzKFFg&hl=en&fs=1&',
'http://www.youtube.com/v/swb8AEcRJhY&hl=en&fs=1&');
$total = count($video_array);
$random = (mt_rand()%$total);
$video = "$video_array[$random]";
?>
<html>
<head>
<title>Random YouTube Video - Array</title>
<style type="text/css">
#example {
width:425px;
height:344px;
position:absolute;
}
</style>
</head>
<body>
<div id="example">
<object width="425" height="344">
<param name="movie" value="<?php echo $video; ?>"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src="<?php echo $video; ?>" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344">
</embed></object>
</div>
</body>
</html>
|
|
Add to del.icio.us
Can you digg it?
|
|
|
07-04-2009, 07:55 AM
|
|
#5
|
 |
|
SuperHero (Level 14)
Join Date: Jun 2007
Location: Crewe, Cheshire
Posts: 260
|
or if you dont want too use a datebase you can do it with an array -
PHP Code:
<html>
<head>
<title>
Random Youtube Video Displayer
</title>
<style type="text/css">
#example {
width: 425px;
height: 344px;
position: absolute;
}
</style>
</head>
<body>
<?php
$videos = array('http://www.youtube.com/v/KPN581r5cS0&hl=en&fs=1&','http://www.youtube.com/v/nJq5kvEO3Uo&hl=en&fs=1&','http://www.youtube.com/v/n9AcG0glVu4&hl=en&fs=1&');
$rand = rand(0,2);
$video = $videos[$rand];
?>
<div id="example">
<object width="425" height="344">
<param name="movie" value="<?php echo $video; ?>"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src="<?php echo $video; ?>" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344">
</embed></object>
</div>
</body>
</html>
Hope this helps =]
|
|
Add to del.icio.us
Can you digg it?
|
|
|
07-04-2009, 08:00 AM
|
|
#6
|
 |
|
SuperHero (Level 14)
Join Date: Jun 2007
Location: Crewe, Cheshire
Posts: 260
|
damn i so should of refreshed before posting i was typing it all out and i sent it and boom the same solution above me xD. I was like did i double post?? :S xD ahhh well nevermind.
Just for refrense Johns method id better than mine so if you go for the array method, user his =]
|
|
Add to del.icio.us
Can you digg it?
|
|
|
07-04-2009, 08:06 AM
|
|
#7
|
 |
|
Blonde Bimbo
Join Date: Jul 2004
Posts: 2,197
|
Or :
PHP Code:
<?php
$video_array = array
('http://www.youtube.com/v/rMNNDINCFHg&hl=en&fs=1&',
'http://www.youtube.com/v/bDF6DVzKFFg&hl=en&fs=1&',
'http://www.youtube.com/v/swb8AEcRJhY&hl=en&fs=1&');
shuffle( $video_array );
$video = $video_array[0];
?>
¥
__________________
I may have opened the door, but you entered of your own free will
|
|
Add to del.icio.us
Can you digg it?
|
|
|
07-04-2009, 10:23 PM
|
|
#8
|
 |
|
Catapulted
Join Date: Dec 2005
Location: Within the division of zero
Posts: 5,858
|
Really, the modulus made more sense than the shuffle(). I think you may want array_rand() instead. shuffle() randomizes the array in place, array_rand() selects keys within the range of the array.
PHP Code:
<?php $video_array = array ('http://www.youtube.com/v/rMNNDINCFHg&hl=en&fs=1&', 'http://www.youtube.com/v/bDF6DVzKFFg&hl=en&fs=1&', 'http://www.youtube.com/v/swb8AEcRJhY&hl=en&fs=1&'); $video = $video_array[array_rand($video_array)];
*shrug*
What did not make sense at all was this:
PHP Code:
$video = "$video_array[$random]";
Why are you quoting it?
|
|
Add to del.icio.us
Can you digg it?
|
|
|
07-07-2009, 12:42 AM
|
|
#9
|
 |
|
Novice (Level 1)
Join Date: Jun 2009
Posts: 6
|
The only problem is I'm not familiar with PHP.
I know enough of html and a little of CSS but I'm still pretty new to the game.
for PHP is it similar to CSS. Would I have to make its own separate file to which to link?
|
|
Add to del.icio.us
Can you digg it?
|
|
|
07-07-2009, 01:41 AM
|
|
#10
|
 |
|
Lord (Level 16)
Join Date: Nov 2007
Location: Chicago, IL. USA
Posts: 546
|
No, you'd take your .html file and rename it to end in .php, and then you can pick your choice of solutions from the above, insert, and it should work.
|
|
Add to del.icio.us
Can you digg it?
|
|
|
08-06-2009, 07:56 AM
|
|
#12
|
 |
|
Novice (Level 1)
Join Date: Jul 2009
Posts: 1
|
insert in database
how can I on separte page insert the links video in database? Can someone help me?
Thanks
Quote:
Originally Posted by john-formby
Hi,
Another option would be to store the links in a database and use a query to echo a random video. Here is an example for you:
Database Table
Code:
CREATE TABLE `arcadianrock` (
`vID` int(5) NOT NULL auto_increment,
`videolink` varchar(200) NOT NULL,
PRIMARY KEY (`vID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
--
-- Dumping data for table `arcadianrock`
--
INSERT INTO `arcadianrock` (`vID`, `videolink`) VALUES
(1, 'http://www.youtube.com/v/rMNNDINCFHg&hl=en&fs=1&'),
(2, 'http://www.youtube.com/v/bDF6DVzKFFg&hl=en&fs=1&');
index.php
PHP Code:
<?php
$dbHost = "localhost";
$dbUser = "username";
$dbPass = "password";
$dbname = "htmlforums";
$db = mysql_connect($dbHost,$dbUser,$dbPass);
mysql_select_db($dbname,$db);
$sql = mysql_query("SELECT * FROM arcadianrock ORDER BY RAND() LIMIT 1");
$row = mysql_fetch_array($sql);
?>
<html>
<head>
<title>Random YouTube Video</title>
<style type="text/css">
#example {
width:425px;
height:344px;
position:absolute;
}
</style>
</head>
<body>
<div id="example">
<object width="425" height="344">
<param name="movie" value="<?php echo $row['videolink']; ?>"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src="<?php echo $row['videolink']; ?>" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344">
</embed></object>
</div>
</body>
</html>
|
|
|
Add to del.icio.us
Can you digg it?
|
|
 |
|
KEEP TABS |
|
SPONSORS |
| |
|
| |
|
|
| |
|