Zola Posted March 15, 2012 Share Posted March 15, 2012 Hello, I have been using a random text script to display a useful tip to the user when they land on a certain page. This is how the script looks: <?php $random_text = array("This is an example tip", "This is another example of a tip", "And another...", "And one more"); $sizeof = count($random_text); $random = (rand()%$sizeof); print("$random_text[$random]"); ?> At the moment the tip will display randomly everytime the page is loaded. Is there any way I can add a small button that says "Give me another" or something, so that when they click it another random fact will come out? If possible I would like to avoid them having to reload the page everytime. Any help is greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/258984-random-statement-script/ Share on other sites More sharing options...
Muddy_Funster Posted March 15, 2012 Share Posted March 15, 2012 as PHP is run on the server, not the client, the only way you could do this would be to load the info into a javascript array and have an onClick event or use a form button and AJAX to reload the innerHTML of a div on your page. once PHP has done processing that's it without a full page refresh. Quote Link to comment https://forums.phpfreaks.com/topic/258984-random-statement-script/#findComment-1327622 Share on other sites More sharing options...
Zola Posted March 15, 2012 Author Share Posted March 15, 2012 Hmm I'll maybe leave it as it is. Thanks for the help! Quote Link to comment https://forums.phpfreaks.com/topic/258984-random-statement-script/#findComment-1327636 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.