[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

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


Closed Thread
 
LinkBack Thread Tools
Old 05-06-2007, 07:39 AM   #1 (permalink)
Senior Member
 
Join Date: Dec 2004
Location: Burlington, Vermont
Posts: 1,043
1,086.90 NP$ (Donate)

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
Automotive SEO

For Sale: Co-Sign.com | Skiny.net | CSIFAQ.com | FuelBank.net | Jibbar.com |
dan_Vt is offline  
Old 05-06-2007, 09:02 AM   #2 (permalink)
NamePros Member
 
jabba_29's Avatar
 
Join Date: Mar 2007
Location: Finland
Posts: 29
5.00 NP$ (Donate)

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, 11:24 AM   #3 (permalink)
Senior Member
 
Join Date: Dec 2004
Location: Burlington, Vermont
Posts: 1,043
1,086.90 NP$ (Donate)

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
Automotive SEO

For Sale: Co-Sign.com | Skiny.net | CSIFAQ.com | FuelBank.net | Jibbar.com |
dan_Vt is offline  
Old 05-06-2007, 11:51 AM   #4 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
 
Join Date: Feb 2006
Posts: 2,801
56.00 NP$ (Donate)

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))]);
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, 02:26 PM   #5 (permalink)
Senior Member
 
Join Date: Dec 2004
Location: Burlington, Vermont
Posts: 1,043
1,086.90 NP$ (Donate)

dan_Vt is a jewel in the roughdan_Vt is a jewel in the roughdan_Vt is a jewel in the rough


Quote:
Originally Posted by Dan
PHP Code:
<?php

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

$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
Automotive SEO

For Sale: Co-Sign.com | Skiny.net | CSIFAQ.com | FuelBank.net | Jibbar.com |
dan_Vt is offline  
Old 05-06-2007, 02:39 PM   #6 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
 
Join Date: Feb 2006
Posts: 2,801
56.00 NP$ (Donate)

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, 05:36 PM   #7 (permalink)
Senior Member
 
Join Date: Dec 2004
Location: Burlington, Vermont
Posts: 1,043
1,086.90 NP$ (Donate)

dan_Vt is a jewel in the roughdan_Vt is a jewel in the roughdan_Vt is a jewel in the rough


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

it won't let me give you more rep
__________________
Vermont SEO
Automotive SEO

For Sale: Co-Sign.com | Skiny.net | CSIFAQ.com | FuelBank.net | Jibbar.com |
dan_Vt is offline  
Old 06-03-2007, 11:05 AM   #8 (permalink)
Danltn.com
 
Daniel's Avatar
 
Join Date: May 2007
Location: Danltn.com / Nottingham, UK
Posts: 1,201
13.51 NP$ (Donate)

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, 11:15 AM   #9 (permalink)
NPQ's PA, Slave, and On Call Coder

Technical Services


 
Eric's Avatar
 
Join Date: Mar 2005
Posts: 4,545
0.71 NP$ (Donate)

Eric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond repute

Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse
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>
</object>
YT;
?>
__________________
Eric is offline  
Old 06-03-2007, 01:14 PM   #10 (permalink)
Senior Member
 
Join Date: Dec 2004
Location: Burlington, Vermont
Posts: 1,043
1,086.90 NP$ (Donate)

dan_Vt is a jewel in the roughdan_Vt is a jewel in the roughdan_Vt is a jewel in the rough


Quote:
Originally Posted by SecondVersion
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>
</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
Automotive SEO

For Sale: Co-Sign.com | Skiny.net | CSIFAQ.com | FuelBank.net | Jibbar.com |
dan_Vt is offline  
Old 06-03-2007, 01:16 PM   #11 (permalink)
NPQ's PA, Slave, and On Call Coder

Technical Services


 
Eric's Avatar
 
Join Date: Mar 2005
Posts: 4,545
0.71 NP$ (Donate)

Eric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond repute

Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse
No problem.
__________________
Eric is offline  
Old 06-03-2007, 04:34 PM   #12 (permalink)
New Member
 
Join Date: Jun 2007
Posts: 9
0.00 NP$ (Donate)

JRWill is an unknown quantity at this point


That's very interesting. Will try it sometimes.
JRWill is offline  
Old 06-03-2007, 05:23 PM   #13 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
 
Join Date: Feb 2006
Posts: 2,801
56.00 NP$ (Donate)

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
Quote:
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, 05:45 PM   #14 (permalink)
NPQ's PA, Slave, and On Call Coder

Technical Services


 
Eric's Avatar
 
Join Date: Mar 2005
Posts: 4,545
0.71 NP$ (Donate)

Eric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond repute

Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse
Quote:
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)]);
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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 06:00 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85