PDA

View Full Version : [PHP|Javascript] HELP!!



iLogan
22-12-2010, 02:01 PM
At the moment on my page I've got YouTube playing one track,


<object width="0" height="0"><param name="movie" value="http://www.youtube.com/v/ST2H8FWDvEA?fs=1&amp;hl=en_GB&autoplay=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/ST2H8FWDvEA?fs=1&amp;hl=en_GB&autoplay=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="0" height="0"></embed></object><br>

Is there a PHP or Javascript piece of code so on refresh that code changes, so I can set different songs?

Remel

LMS16
22-12-2010, 02:40 PM
<?php
echo rand(1, 10); // 1 being the first track & 10 being the last
?>

enjoy :)

Lew.

iLogan
22-12-2010, 02:43 PM
Thanks -

but where do you define what 1 - 10 is?

LMS16
22-12-2010, 04:17 PM
Thanks -

but where do you define what 1 - 10 is?

That is how you'd get a random number.

Can you explain what exactly your trying to do then maybe I could help better.

Lew.

Trinity
22-12-2010, 04:36 PM
<?php

// Set the video id of each track
// You can add as many tracks as you want and the count() function will adjust the range used in rand()
$trackArray[] = 'ST2H8FWDvEA';
$trackArray[] = 'ST2H8FWDvEA';
$trackArray[] = 'ST2H8FWDvEA';
$trackArray[] = 'ST2H8FWDvEA';
$trackArray[] = 'ST2H8FWDvEA';

// Select a random track
$id = rand(0, count($trackArray));
$track = $trackArray[$id];

echo "<object width='0' height='0'><param name='movie' value='http://www.youtube.com/v/{$track}?fs=1&amp;hl=en_GB&autoplay=1'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed src='http://www.youtube.com/v/{$track}?fs=1&amp;hl=en_GB&autoplay=1' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='0' height='0'></embed></object><br>"

?>


Not tested but it should work, although there's almost definitely a nicer way of doing it.
I'm assuming you want it to be random, but I'm probably wrong.

Want to hide these adverts? Register an account for free!