Go Back  HTML Forums - Free Webmaster Forums and Help Forums > WEBSITE DEVELOPMENT > Server Side Programming > PHP Programming
User Name:
Password:
 

Reply
Thread Tools   Display Modes
  View First Unread
 
Old 07-04-2009, 12:20 AM
  #1
Arcadianrock
Novice (Level 1)
 
Join Date: Jun 2009
Posts: 6
iTrader: (0)
Arcadianrock is an unknown quantity at this point
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.
Arcadianrock is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 07-04-2009, 01:05 AM
  #2
Sawtooth500
Lord (Level 16)
 
Sawtooth500's Avatar
 
Join Date: Nov 2007
Location: Chicago, IL. USA
Posts: 546
iTrader: (0)
Sawtooth500 is on a distinguished road
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.
__________________
-Taras Hryniw

http://www.waltonstreetwebdesign.com
Sawtooth500 is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 07-04-2009, 07:27 AM
  #3
john-formby
Paladin (Level 15)
 
john-formby's Avatar
 
Join Date: Aug 2005
Location: Formby, UK
Posts: 394
iTrader: (0)
john-formby is on a distinguished road
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>
john-formby is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 07-04-2009, 07:36 AM
  #4
john-formby
Paladin (Level 15)
 
john-formby's Avatar
 
Join Date: Aug 2005
Location: Formby, UK
Posts: 394
iTrader: (0)
john-formby is on a distinguished road
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>
john-formby is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 07-04-2009, 07:55 AM
  #5
chuckymong
SuperHero (Level 14)
 
chuckymong's Avatar
 
Join Date: Jun 2007
Location: Crewe, Cheshire
Posts: 260
iTrader: (0)
chuckymong will become famous soon enough
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 =]
__________________
Portfolio Site: Chucky-mong - New name soon!
chuckymong is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 07-04-2009, 08:00 AM
  #6
chuckymong
SuperHero (Level 14)
 
chuckymong's Avatar
 
Join Date: Jun 2007
Location: Crewe, Cheshire
Posts: 260
iTrader: (0)
chuckymong will become famous soon enough
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 =]
__________________
Portfolio Site: Chucky-mong - New name soon!
chuckymong is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 07-04-2009, 08:06 AM
  #7
¥åßßå
Blonde Bimbo
 
¥åßßå's Avatar
 
Join Date: Jul 2004
Posts: 2,197
iTrader: (0)
¥åßßå is a name known to all¥åßßå is a name known to all¥åßßå is a name known to all¥åßßå is a name known to all¥åßßå is a name known to all¥åßßå is a name known to all
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

¥åßßå is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 07-04-2009, 10:23 PM
  #8
erisco
Catapulted
 
erisco's Avatar
 
Join Date: Dec 2005
Location: Within the division of zero
Posts: 5,858
iTrader: (0)
erisco will become famous soon enougherisco will become famous soon enough
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?
erisco is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 07-07-2009, 12:42 AM
  #9
Arcadianrock
Novice (Level 1)
 
Join Date: Jun 2009
Posts: 6
iTrader: (0)
Arcadianrock is an unknown quantity at this point
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?
Arcadianrock is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 07-07-2009, 01:41 AM
  #10
Sawtooth500
Lord (Level 16)
 
Sawtooth500's Avatar
 
Join Date: Nov 2007
Location: Chicago, IL. USA
Posts: 546
iTrader: (0)
Sawtooth500 is on a distinguished road
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.
__________________
-Taras Hryniw

http://www.waltonstreetwebdesign.com
Sawtooth500 is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 07-07-2009, 07:06 PM
  #11
Arcadianrock
Novice (Level 1)
 
Join Date: Jun 2009
Posts: 6
iTrader: (0)
Arcadianrock is an unknown quantity at this point
Got it, works great. Thankyou
Arcadianrock is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 08-06-2009, 07:56 AM
  #12
samal
Novice (Level 1)
 
Join Date: Jul 2009
Posts: 1
iTrader: (0)
samal is an unknown quantity at this point
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 View Post
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>
samal is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote

Reply
KEEP TABS
SPONSORS
 
Boxedart
 
 


 
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
  
 
 
 



 
  POSTING RULES
 
 
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Thread Tools
Display Modes

Forum Jump

 

All times are GMT -5. The time now is 02:23 PM.

   

Mascot team created by Drawshop.com

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.