keegan90 Posted June 7, 2010 Share Posted June 7, 2010 Hi there, first post so hope it goes well Im trying to generate statistics on which quote will be displayed each time i refresh the page. I've stored 10 famous quotes in the $famous_quotes array but have no idea on how to find out which 1 has been selected and then to generate the stats for that quote (if its even possible!!!) Have been stuck on this problem for 4 days now!! So any help would be appreciated. This is the code used for storing and randomising my quotes. <?php $famous_quotes=array("Imagination is more important than knowledge - Albert Einstein", "If music be the food of love, play on - Shakespeare", "Never let your sense of morals get in the way of doing what's right - Isaac Asimov", "Obstacles are those frightful things you see when you take your eyes off the goal - Henry Ford", "When you come to a fork in the road, take it - Yogi Berra", "We may affirm absolutely that nothing great in the world has been accomplished without passion - Hegel", "The life which is unexamined is not worth living - Socrates", "Live as if you were to die tomorrow. Learn as if you were to live forever - M.K. Gandhi", "What you get by achieving your goals is not as important as what you become by achieving your goals - Zig Ziglar", "A lie gets halfway around the world before the truth has a chance to get its pants on - Sir Winston Churchill"); print_r($famous_quotes); $random = rand(0, 9); echo $famous_quotes[$random]; ?> Have tried things like <?php if ($random = 1) { $a = 0; $a++; } if ($random = 2) { $b = 0; $b++; } ?> to try store which quote its printing out and then create stats using $a for first quote, $b for second etc etc... But nothing works!!! Quote Link to comment Share on other sites More sharing options...
ldb358 Posted June 7, 2010 Share Posted June 7, 2010 your condition should look like this: if ($random == 0) { $a = 0; $a++; } Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 7, 2010 Share Posted June 7, 2010 You really should be using a database here. If you don't you have no way of storing the number times a particular quote has been used. Ken Quote Link to comment Share on other sites More sharing options...
keegan90 Posted June 7, 2010 Author Share Posted June 7, 2010 Thanks ldb358, that extra equals sign was what made it possible. And thanks for your advice kenrbnsn, i did use sessions in the end. it all works perfectly now 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.