how to change random content to repeating

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dweezel44
Forum Newbie
Posts: 3
Joined: Mon Oct 20, 2008 9:23 am

how to change random content to repeating

Post by dweezel44 »

Hi - I have images randomly cycling on a home page of a site that i am working on and would like to change it so it goes in order and then repeats. I am stumped and can't find the correct term to use.
Here is the code I am working with.

$random_content="random.htm";
$random_content=file("$random");
$display=rand(0, sizeof($random)-1);
echo $random_content[$display];

also this code:

/*
generate a random number between zero
and the number of quotes minus one
*/
$rand = rand(0, (count($quotes)-1));

// output the random quote
echo $quotes[$rand];

Any help would be appreciated :)
Thank you! :D
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: how to change random content to repeating

Post by aceconcepts »

User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: how to change random content to repeating

Post by onion2k »

How is sorting going to help? The issue here is with the stateless nature of the internet. You need to record which item was last displayed to the user and use that value to find the next one ... I suggest you read up on "sessions".
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: how to change random content to repeating

Post by aceconcepts »

Are we not talking about random integer values he wants ordered?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: how to change random content to repeating

Post by onion2k »

I think he wants a quote on the page that starts on Quote 1, then increments through all the available quotes, and loops when it gets to the end. A value denoting which quote the user has last seen stored in the session that increments on each page load is the simplest solution.
dweezel44
Forum Newbie
Posts: 3
Joined: Mon Oct 20, 2008 9:23 am

Re: how to change random content to repeating

Post by dweezel44 »

thank you. i will research sessions and let you know how it works out. thanks all! :)
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: how to change random content to repeating

Post by aceconcepts »

onion2k wrote:How is sorting going to help?
Too right - oops my bad :lol:
dweezel44
Forum Newbie
Posts: 3
Joined: Mon Oct 20, 2008 9:23 am

Re: how to change random content to repeating

Post by dweezel44 »

aceconcepts - i am talking about random integer values which i would like to change to in order and repeating or just repeating. What do you suggest i change it to or research on.
Thanks :)
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: how to change random content to repeating

Post by VladSun »

There are 10 types of people in this world, those who understand binary and those who don't
Post Reply