Jump to content

Archived

This topic is now archived and is closed to further replies.

Rianna

Need help with php random string please.

Recommended Posts

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!


$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.

Share this post


Link to post
Share on other sites
If you number them 0 - 6, zero being Sundays text and 6 being Saturdays text, you can grab todays text with date("w").

Share this post


Link to post
Share on other sites
Not sure what you mean, can you show me a string for this please, to use instead of mine. Thank you very much!

Share this post


Link to post
Share on other sites
[code]<?php
$days = array(
    'Sundays text',
    'Mondays text,
    /* etc */
    'Saturdays text'
);

echo $days[array_rand($days)];

?>[/code]

Share this post


Link to post
Share on other sites
[quote author=Rianna link=topic=106716.msg427550#msg427550 date=1157348033]
Not sure what you mean, can you show me a string for this please, to use instead of mine. Thank you very much!
[/quote]
Sure, your file would contain:
0-Sundays text
1-Mondays text
2-Tuesdays text
3-Wednesdays text
4-Thursdays text
5-Fridays text
6-Saturdays text

And to get todays text, you'd do something like this:
$banner_no = date("w");

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.