Horsecope For Weekly.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
phpbaby2009
Forum Commoner
Posts: 31
Joined: Sun Nov 16, 2008 8:20 pm

Horsecope For Weekly.

Post by phpbaby2009 »

I got my brain twisted... H E L P :banghead:

$storedArray=Array
("horscopeCategory1" => "you are going to marry this week",
"horscopeCategory2" => "you will be rich this week",
"horscopeCategory3" => "your wife will beat you up for sure",
"horscopeCategory4" => "are u sure? she knows you are secretly using messengers. reduce!",
"horscopeCategory5" => "the more you give the more you will get. start giving MORE today!"
"horscopeCategory1" => "you are going to marry this week",
"horscopeCategory2" => "take care of your health, i see some bad sign this week coming at ya",
"horscopeCategory3" => "little things in life is what makes it beautiful",
"horscopeCategory4" => "life is what is and you are doing a great job",
"horscopeCategory5" => "you will be getting a promotion soon, keep coding dude"
"horscopeCategory1" => "when the life is hard consider problems are different",
"horscopeCategory2" => "go ahead give a dollar to lotto or it might give you many fold back",
"horscopeCategory3" => "your search in google php horsecope and nothing came up was last week so relax dude!",
"horscopeCategory4" => "are u sure? she knows you are secretly using messengers. reduce!",
"horscopeCategory5" => "your friend seems to be offtrack. u can tell his wife about it..lol"
)

$weekStart="Monday"


How can the program:

(a) RANDOMLY pick a horsecope
(b) Display it same all days of the week
(c) Come next week, pick a different one
(d) Program ensures RANDOM pick is unique/i.e. it's not included in other horsecopeCategories.


I have about 200KB array with valid horoscopes. Can you please help guys ? I did search here and many days in google and in vain. I am so sure this will come in handy to so many of those like me. If you aren't into horsecope, your technique to let the program CHANGE a given text on a weekly basis would be awesome.

(a) Can we store the data on a cookie and come next monday we change it ? But the program would be stupid at least if the user has disabled cookies. I guess I could use a flatfile to store and check if the displayed horsecope is about to expire ???? Anyidea without using a flatfile etc ? :drunk:
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Horsecope For Weekly.

Post by requinix »

phpbaby2009 wrote:I have about 200KB array with valid horoscopes
So you've proved that you know how to spell the word...


(a) You can use mt_rand.
(b and c) Look into date to tell you the week number. Combine that with some other information such as the month and year, feed it into mt_srand, and you'll have a source of random numbers by week.
(b) No idea what you mean by that.
User avatar
phpbaby2009
Forum Commoner
Posts: 31
Joined: Sun Nov 16, 2008 8:20 pm

Re: Horsecope For Weekly.

Post by phpbaby2009 »

thanks for whatever.... well, seems like nobody is interested. Am I asking something so useless ?

Then, let me ask you.

Suppose you wanted to rotate a banner or text on your website not every day but once every week, how would you do that ?
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Horsecope For Weekly.

Post by papa »

Well cookies might do it for that type of application if no user session is available. You can also work with IP's but is not that solid.

Make an effort and try yourself first. Isn't that hard to display a whorescope per week but noone will program for you.

peace
User avatar
phpbaby2009
Forum Commoner
Posts: 31
Joined: Sun Nov 16, 2008 8:20 pm

Re: Horsecope For Weekly.

Post by phpbaby2009 »

papa, thanks for clapping. ok. so it's all random, ha ? even so, i got a problem and there is no ANSWER to this question on the Web. I guess it's kind a silly but problem is a problem, right papa?

Can you please throw some ways to solve this problem.... please !!!

(A) I want to PICK A Random Number which needs to remain the same for 24 hours.... any idea on how to do this guys ?
Please don't suggest on using cookies because... if the user tries to check the script using two computers having different IP address.. program may show different result for the same Zodiac sign ! LOL

Nothing much on internet and i can't seem to get a FIXED Random Number that will stay the same for the entire DAY. Sounds funny even to talk about it... :oops: :oops: :oops:

Well, I hope I am not giving you too much trouble. If you help me, I will thank you million times.... warm hugs. :oops: :oops: :roll:
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Horsecope For Weekly.

Post by Mark Baker »

Try this random number generator several times a day for the next few weeks:

Code: Select all

 
<?php
 
$salt = date('YW');
srand($salt);
for ($x=0;$x<10;$x++) {
    echo rand(1,10).'<br />';
}
 
?>
 
Note that the week starts on Monday
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Horsecope For Weekly.

Post by papa »

phpbaby2009 wrote:papa, thanks for clapping. ok. so it's all random, ha ? even so, i got a problem and there is no ANSWER to this question on the Web. I guess it's kind a silly but problem is a problem, right papa?

Can you please throw some ways to solve this problem.... please !!!
Not my intention to be an ass but are you clear of what you want to do ?

First it's a week, then it's 24 hours :)

So you want a horoscope to be displayed once every 24 hours depending on who's on your site? That's going to be tricky not using session, cookies or IP.
User avatar
phpbaby2009
Forum Commoner
Posts: 31
Joined: Sun Nov 16, 2008 8:20 pm

Re: Horsecope For Weekly.

Post by phpbaby2009 »

[quote="papa"][quote="phpbaby2009"]papa, thanks for clapping. ok. so it's all random, ha ? even so, i got a problem and there is no ANSWER to this question on the Web. I guess it's kind a silly but problem is a problem, right papa?

Not really, thanks for shaking this thread. I almost gave up. Are there less programmers interested in Horoscope than others? Is that why we don't have any script of this kind ?

Here is what I wanted to do--- It doesn't seem to be so complicated.

He have these categories, each one is a text file, each have at least 52 or more lines of horoscopes, 1 for each week.

Aries.txt
Taurus.txt
Gemini.txt
Cancer.txt
Leo.txt
Virgo.txt
Libra.txt
Scorpio.txt
Sagittarius.txt
Capricorn.txt
Aquarius.txt
Pisces.txt

Each entries have been written by somone who has done Ph.D in Astrology, not by me, yes, not by any dummies like me!!

So, each entry is valid.

Yes, if you want to see your future, you can use this script, so why not write it, man!! Everyone!! If you are laughing, that's because you aren't taking it seriously.

how to handle this issue, that's where I am stuck.
a) pick a line from a text file and show it to the user making sure these:

(a) horoscope changes every day
(b) horoscope can not be repeated
(c) horoscope must not be random
(d) horoscope will change once every week

that's it.
User avatar
phpbaby2009
Forum Commoner
Posts: 31
Joined: Sun Nov 16, 2008 8:20 pm

Re: Horsecope For Weekly.

Post by phpbaby2009 »

Mark Baker wrote:Try this random number generator several times a day for the next few weeks:

Code: Select all

 
<?php
 
$salt = date('YW');
srand($salt);
for ($x=0;$x<10;$x++) {
    echo rand(1,10).'<br />';
}
 
?>
 
Note that the week starts on Monday
Mark Baker, thank you so much for that tip. I'm really stuck though, cause I need the number to remain same for 24 hours, change on the next day. Thank you for taking your time.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Horsecope For Weekly.

Post by Mark Baker »

phpbaby2009 wrote:
Mark Baker wrote:Try this random number generator several times a day for the next few weeks:
Mark Baker, thank you so much for that tip. I'm really stuck though, cause I need the number to remain same for 24 hours, change on the next day. Thank you for taking your time.
Your original request was for the random number to remain the same throughout the week, and then change the following week. This is the line of code which determines that:

Code: Select all

$salt = date('YW');
If you take a look at the date() function in PHP, you should be able to figure out what change to make now that you want it on a daily basis.
Post Reply