Results 1 to 3 of 3

Thread: need explanation for random display user

  1. #1
    Join Date
    Oct 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default need explanation for random display user

    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

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    one user per day? or just a random username for every page load?

  3. #3
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    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:

    Code:
    $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
    Last edited by JasonDFR; 10-15-2011 at 11:13 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •