Jump to content


Photo

Need help with php random string please.


  • Please log in to reply
4 replies to this topic

#1 Rianna

Rianna
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 03 September 2006 - 09:46 AM

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.


#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 03 September 2006 - 10:18 AM

If you number them 0 - 6, zero being Sundays text and 6 being Saturdays text, you can grab todays text with date("w").

#3 Rianna

Rianna
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 04 September 2006 - 05:33 AM

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

#4 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 04 September 2006 - 09:12 AM

<?php
$days = array(
    'Sundays text',
    'Mondays text,
    /* etc */
    'Saturdays text'
);

echo $days[array_rand($days)];

?>


#5 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 04 September 2006 - 10:53 AM

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

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");




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users