PDA

View Full Version : need explanation for random display user



gagalpacaran
10-13-2011, 02:52 PM
Hi everybody,
anyone can help me to explain about displaying random user script? for example, today the web displays "username1" in a DIV section, tomorrow displays "username2", and so on...

Any help would be appreciated
thanks
:)

traq
10-13-2011, 07:40 PM
one user per day? or just a random username for every page load?

JasonDFR
10-15-2011, 11:07 PM
Editing because I just remembered you wanted random users per day. I think you will need a database to do this.

You'll need a table containing rows with dates and a random user.

First you'll query the database to determine if an entry for the current date exists. If one does, just take the username associate with it.

If the date does not exist, you'll select a random user, and create a row with the current date and this user.

Selecting a random username from a database poses some challenges too. Google: random database row

My response before editing:



$usernames = array('username1', 'username2', 'username3', 'username4');

$randomUsername = array_rand($usernames);


If you have your users stored in a database, it becomes more complicated. Google: random database row