Need help with a php random string please.

Discussion in 'PHP' started by Jen-, Sep 3, 2006.

  1. #1
    Hello, I would like to change some php to calling on something by day.
    The one I have only calls on something randomly. Do you know how I can
    alter this string to accomodate this? Thanks! Jen


    $banner_no = (rand()%(count($s_con)-1));

    Just so you know what the above does, gets a random number which is in the content of my file. for instance if I have
    1-some text
    2-different text
    3-some other text

    It grabs one of these numbers and the text along with it to display randomly. I would like it to display by day and in order instead.
     
    Jen-, Sep 3, 2006 IP
  2. drewbe121212

    drewbe121212 Well-Known Member

    Messages:
    733
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    125
    #2
    in order of what? as in 1, 2, 3 as you have it listed?

    If you wanted to get the current day use date("d",time());
     
    drewbe121212, Sep 3, 2006 IP
  3. smatts9

    smatts9 Active Member

    Messages:
    1,089
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    88
    #3
    using date(j); will give you the number of the day from 1-31 in each month.
     
    smatts9, Sep 3, 2006 IP
  4. Jen-

    Jen- Peon

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yes, right now it takes text 1 2 or 3 randomly and displays one of them at a time.

    I would prefer it to take them as text for DAY 1,2, or 3 and in order instead.

    If you guys could give me the whole string it would help a lot. For instance drew, should I use this? $banner_no = date("d",time());

    and smatt how would I use yours? Thank you very much! Jen-
     
    Jen-, Sep 3, 2006 IP
  5. wmburg

    wmburg Active Member

    Messages:
    300
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #5
    The only difference between theirs is

    date("d") gives you the day with leading zeros
    date("j") gives you the day without leading zeros

    You do not need that second parameter -- time() -- this is the default value.

    So you want

    $banner_no = date("j");
    PHP:
     
    wmburg, Sep 3, 2006 IP
  6. smatts9

    smatts9 Active Member

    Messages:
    1,089
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    88
    #6
    Definitely mine ;)
     
    smatts9, Sep 3, 2006 IP
  7. Jen-

    Jen- Peon

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    WMBurg thank you!!! I won't know until tomorrow, but it is showing todays test.banner.
     
    Jen-, Sep 4, 2006 IP
  8. Jen-

    Jen- Peon

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    You did it WMBurg, thanks!!! :)
     
    Jen-, Sep 6, 2006 IP