jonoc33 Posted February 19, 2008 Share Posted February 19, 2008 Ok, as a joke to a bunch of mates on our forum we added a Water cooler (they requested it) that, if you click it, it adds a session and on the next page and I need it to come up with a random result. Say for example after you click it, on the next page it shows at random 1 of these: "You just drank urine." "You just ate a bug." "You feel refreshed." "Someone took a dump in your cup." "You found a coin at the bottom of your cup and accidentally drank it." "Someone spiked your drink. You feel tipsy." etc. How would I do this? Quote Link to comment Share on other sites More sharing options...
Sulman Posted February 19, 2008 Share Posted February 19, 2008 Put them all into an array and then get a random element: $result=array(); $result[0]="You just drank urine."; $result[1]="You just ate a bug."; $result[2]="You feel refreshed."; $result[3]="Someone took a dump in your cup."; $result[4]="You found a coin at the bottom of your cup and accidentally drank it."; $result[5]="Someone spiked your drink. You feel tipsy."; $random=rand(0, 5); echo $result[$random]; Quote Link to comment Share on other sites More sharing options...
jonoc33 Posted February 19, 2008 Author Share Posted February 19, 2008 Thanks, that worked. Quote Link to comment Share on other sites More sharing options...
rameshfaj Posted February 19, 2008 Share Posted February 19, 2008 You can store the variable in session using: $_SESSION["items"]="items";//the items can be array object too and later can be retrieved as you like............ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.