PDA

View Full Version : Need a code..



Meanies
27-07-2007, 12:52 PM
That randomizes content.
So every time you reload the page, a different thing shows in a certain part of the layout.

A bit like the old habbo spotlight thing on the homepage.

Please :)

Decode
27-07-2007, 01:06 PM
<script language="JavaScript">
<!--
function random_text()
{};
var random_text = new random_text();
var number = 0;
random_text[number++] = "Content 1 Goes Here"
random_text[number++] = "Content 2 Goes Here"
random_text[number++] = "Content 3 Goes Here"
random_text[number++] = "Content 4 Goes Here"

var random_number = Math.floor(Math.random() * number);

document.write(random_text[random_number]);
--></script>


That should work :)

Meanies
27-07-2007, 02:16 PM
tyvm :)

+rep

Invent
27-07-2007, 05:30 PM
Doing it via PHP would be better, tbh. (So that the content shows in older browsers).



<?php

$content[ 1 ] = "Content piece 1";
$content[ 2 ] = "Content piece 2";
$content[ 3 ] = "Content piece 3";
/* To add a new piece of content just copy the above code and change the '3' to a '4', etc */

$rand = rand( 1, 3 /* Change the "3" to the amount of different content pieces */);

echo $content[$rand];

?>
That's not the best way to do it in PHP, but it still works :p

Meanies
27-07-2007, 09:59 PM
Thanks to you both, but would you be able to do the full thing for me, which ever way i try it i do it wrong and don't really udnerstand php :P

What i want is 10 different things to be randomized.
So in each content bit can you put
<a href="http://www.habbo.co.uk/home/NAME">NAME</a>
andd

<img src="http://www.habbo.co.uk/habbo-imaging/avatarimage?user=NAME&action=wve&frame=3&direction=4&head_direction=4&gesture=sml&img_format=gif">
Thanks :P
Just i keep going wrong :( -stupid-
+rep again to whoever does it first ;P

Invent
27-07-2007, 10:34 PM
<?php

$habbo[1] = "Invent!";
$habbo[2] = "ReviewDude";
$habbo[3] = "Archivist";
$habbo[4] = "iSocks";
$habbo[5] = "Lost_Witness";
$habbo[6] = "HelKat";
$habbo[7] = "UKChaserAl";
$habbo[8] = "Disarno";
$habbo[9] = "RedTiz";
$habbo[10] = "Heidster";

/* No more editing needed! */

$i = "0";

foreach ($habbo as $habbos) {

$i++;

}

function image( $name )
{

echo( '<a href="http://www.habbo.co.uk/home/'. $name .'">'. $name .'</a><br /><img src="http://www.habbo.co.uk/habbo-imaging/avatarimage?user='. $name .'&action=wve&frame=3&direction=4&head_direction=4&gesture=sml&img_format=gif" alt="'. $name.'" /></a>' );

}


$rand = rand( 1, $i );

image( $habbo[ $rand ] );

?>
To change the current Habbo's just edit the text in the quotes. ( The
"Invent!" part )

To add another Habbo just add:



$habbo[11] = "Habbo Name";
So basically you just change the number in the [] to the the number after the last entry.

P.S: The above code is coded badly, I just made it in 2mins lol.

Mentor
27-07-2007, 10:41 PM
Php version


<?php

// stuff to poke
$stuff[ 0 ] = '<a href="http://www.habbo.co.uk/home/NAME">NAME </a>';
$stuff[ 1 ] = '<a href="http://www.habbo.co.uk/home/NAME">NAME 1</a>';
$stuff[ 2 ] = '<a href="http://www.habbo.co.uk/home/NAME">NAME 2</a>';
$stuff[ 3 ] = '<a href="http://www.habbo.co.uk/home/NAME">NAME 3</a>';
$stuff[ 4 ] = '<a href="http://www.habbo.co.uk/home/NAME">NAME 4</a>';
$stuff[ 5 ] = '<a href="http://www.habbo.co.uk/home/NAME">NAME 5</a>';
$stuff[ 6 ] = '<a href="http://www.habbo.co.uk/home/NAME">NAME 6</a>';
$stuff[ 7 ] = '<img src="http://www.habbo.co.uk/habbo-imaging/avatarimage?user=NAME&action=wve&frame=3&direction =4&head_direction=4&gesture=sml&img_format=gif">';
$stuff[ 8 ] = '<img src="http://www.habbo.co.uk/habbo-imaging/avatarimage?user=NAME&action=wve&frame=3&direction =4&head_direction=4&gesture=sml&img_format=gif"> 2';

//Dont poke this, it'll work, just change values above and add/remove from em
$display=rand(0, sizeof($stuff)-1);
echo $stuff[$display];
?>

Invent
27-07-2007, 10:42 PM
Lmao, forgot about 'sizeof' and 'count'.

Meanies
27-07-2007, 10:56 PM
Lmao, forgot about 'sizeof' and 'count'.

Are they important? :o

+rep to both btw :)
Ty

edit; need to spread before i can give to invent ;D

Invent
27-07-2007, 11:00 PM
Nah, its just a quicker way of doing all that $i stuff.

Luckyrare
27-07-2007, 11:10 PM
Are they important? :o

+rep to both btw :)
Ty

edit; need to spread before i can give to invent ;D

both will work, just mentors is quicker x]]

Meanies
27-07-2007, 11:11 PM
Nah, its just a quicker way of doing all that $i stuff.

OK

i've done somethin wrong agen tho ;P Im no good at php.
no idea what though ;S
It says its on line 56 which is
image( $habbo[ $rand ] );
so im guessing i did something to muck up the image? ;S
Anywayy.
Can you make it so it shows the image, aligned to the right from the top.
Then say 'Every week we put 10 random Habbos into the Spotlight! One of this weeks featured Habbos is' and then the habbo name bit

Thanks ;P again:rolleyes:

timROGERS
01-08-2007, 03:59 PM
I was actually about to post about using count as opposed to incrementing it, but Mentor pointed it out before I even saw the thread :P

Lilian
01-08-2007, 04:12 PM
Nice codes :) Good for content use :)

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