NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Displaying a random youtube video from a list

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 05-06-2007, 08:39 AM THREAD STARTER               #1 (permalink)
Senior Member
Join Date: Dec 2004
Location: Burlington, Vermont
Posts: 1,048
dan_Vt is a jewel in the roughdan_Vt is a jewel in the roughdan_Vt is a jewel in the rough
 



Displaying a random youtube video from a list


I've done some searching and can't find this. I'd like a php script that will display a random youtube video picked from a list I create (at a resolution I define).

Anyone know of such a thing?
__________________
Vermont SEO
Tool Band Forum

For Sale: Co-Sign.com
dan_Vt is offline  
Old 05-06-2007, 10:02 AM   #2 (permalink)
NamePros Member
 
jabba_29's Avatar
Join Date: Mar 2007
Location: Finland
Posts: 29
jabba_29 is an unknown quantity at this point
 



If you can't find one, then you will need to make one youself.
If you are creating the list yourself, then you can do a SELECT from your database and use rand() with php or Mysql
Code:
SELECT * FROM table1, table2 WHERE a=b AND c<d -> ORDER BY RAND() LIMIT 1000;
__________________
Regards Jamie

Let the might of your compassion arise to bring a quick end
to the flowing stream of the blood and tears .....
Please hear my anguished words of truth.
jabba_29 is offline  
Old 05-06-2007, 12:24 PM THREAD STARTER               #3 (permalink)
Senior Member
Join Date: Dec 2004
Location: Burlington, Vermont
Posts: 1,048
dan_Vt is a jewel in the roughdan_Vt is a jewel in the roughdan_Vt is a jewel in the rough
 



Thanks for the info. I don't have a database, I was hoping to have a php script that would have the youtube code then pull the video id from a random line of a txt file. Possible?
__________________
Vermont SEO
Tool Band Forum

For Sale: Co-Sign.com
dan_Vt is offline  
Old 05-06-2007, 12:51 PM   #4 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
Join Date: Feb 2006
Posts: 2,796
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
 


Autism Autism Autism Autism Autism Autism Autism
PHP Code:
<?php

$file 
"path/to/text/file.txt";

$data file($file);
$line trim($data[rand(0,count($data))]);
????: NamePros.com http://www.namepros.com/programming/324749-displaying-a-random-youtube-video-list.html
echo 
'<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/'.$line.'"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/'.$line.'" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>';

?>
Dan is offline  
Old 05-06-2007, 03:26 PM THREAD STARTER               #5 (permalink)
Senior Member
Join Date: Dec 2004
Location: Burlington, Vermont
Posts: 1,048
dan_Vt is a jewel in the roughdan_Vt is a jewel in the roughdan_Vt is a jewel in the rough
 



Originally Posted by Dan
PHP Code:
<?php

$file 
"path/to/text/file.txt";
????: NamePros.com http://www.namepros.com/showthread.php?t=324749

$data file($file);
$line trim($data[rand(0,count($data))]);
echo 
'<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/'.$line.'"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/'.$line.'" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>';

?>
Oh man! That's working but sometimes it doesn't load anything (almost like there's a blank line, which there isn't). NPs, rep, nomination for member of the month if you can figure that one out!
__________________
Vermont SEO
Tool Band Forum

For Sale: Co-Sign.com
dan_Vt is offline  
Old 05-06-2007, 03:39 PM   #6 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
Join Date: Feb 2006
Posts: 2,796
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
 


Autism Autism Autism Autism Autism Autism Autism
Does it have the <object... code when nothing appears or does absolutely nothing show up?
Dan is offline  
Old 05-06-2007, 06:36 PM THREAD STARTER               #7 (permalink)
Senior Member
Join Date: Dec 2004
Location: Burlington, Vermont
Posts: 1,048
dan_Vt is a jewel in the roughdan_Vt is a jewel in the roughdan_Vt is a jewel in the rough
 



Originally Posted by Dan
Does it have the <object... code when nothing appears or does absolutely nothing show up?
nothing shows at all when that happens...
????: NamePros.com http://www.namepros.com/showthread.php?t=324749

it won't let me give you more rep
__________________
Vermont SEO
Tool Band Forum

For Sale: Co-Sign.com
dan_Vt is offline  
Old 06-03-2007, 12:05 PM   #8 (permalink)
Danltn.com
 
Daniel's Avatar
Join Date: May 2007
Location: Danltn.com / Nottingham, UK
Posts: 1,201
Daniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond repute
 


Ethan Allen Fund Ethan Allen Fund
$line = trim($data[rand(0,count($data))]); <-- It shows whichever video is in position 0.

If you changed that variable to 3, then it would show position 3 (i.e. the 4th URL).

At least, that's what happeneding on my server.
Daniel is offline  
Old 06-03-2007, 12:15 PM   #9 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
Try array_rand:

PHP Code:
<?php

$file 
'path/to/text/file.txt';

$data file($file);
$line trim($data[array_rand($data)]);

echo <<<YT
<object width="425" height="350">
    <param name="movie" value="http://www.youtube.com/v/
$line"></param>
    <param name="wmode" value="transparent"></param>
    <embed src="http://www.youtube.com/v/
$line" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed>
????: NamePros.com http://www.namepros.com/showthread.php?t=324749
</object>
YT;

?>
Eric is offline  
Old 06-03-2007, 02:14 PM THREAD STARTER               #10 (permalink)
Senior Member
Join Date: Dec 2004
Location: Burlington, Vermont
Posts: 1,048
dan_Vt is a jewel in the roughdan_Vt is a jewel in the roughdan_Vt is a jewel in the rough
 



Originally Posted by SecondVersion
Try array_rand:
????: NamePros.com http://www.namepros.com/showthread.php?t=324749

PHP Code:
<?php

$file 
'path/to/text/file.txt';

$data file($file);
$line trim($data[array_rand($data)]);

echo <<<YT
<object width="425" height="350">
    <param name="movie" value="http://www.youtube.com/v/
$line"></param>
    <param name="wmode" value="transparent"></param>
    <embed src="http://www.youtube.com/v/
$line" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed>
</object>
YT;

?>
That seems to fix the issue I had with it occasionally showing nothing.

Thanks, won't let me send rep again, so NPs on the way.
__________________
Vermont SEO
Tool Band Forum

For Sale: Co-Sign.com
dan_Vt is offline  
Old 06-03-2007, 02:16 PM   #11 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
No problem.
Eric is offline  
Old 06-03-2007, 05:34 PM   #12 (permalink)
New Member
Join Date: Jun 2007
Posts: 9
JRWill is an unknown quantity at this point
 



That's very interesting. Will try it sometimes.
JRWill is offline  
Old 06-03-2007, 06:23 PM   #13 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
Join Date: Feb 2006
Posts: 2,796
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
 


Autism Autism Autism Autism Autism Autism Autism
Originally Posted by SecondVersion
Try array_rand:
Do you know why that worked or why my version randomly didn't work?
Dan is offline  
Old 06-03-2007, 06:45 PM   #14 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
Originally Posted by Dan
Do you know why that worked or why my version randomly didn't work?
Arrays start at key 0, so when you:
PHP Code:
$line trim($data[rand(0,count($data))]); 
If rand returns the total #, there won't be an entry in the array for it.

You'd have to:
PHP Code:
$line trim($data[rand(0,count($data)-1)]); 
????: NamePros.com http://www.namepros.com/showthread.php?t=324749
With array_rand, you don't have to make that adjustment. array_rand is the preferred method for getting random entires from an array anyway.
Eric is offline  
Closed Thread


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


Liquid Web Smart Servers  
All times are GMT -7. The time now is 10:18 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger