cliftonbazaar Posted October 1, 2012 Share Posted October 1, 2012 I have a page that echo's 10 questions so the user can choose one, what I want is a one second delay between each question being displayed, I have tried sleep() in the loop but this doesn't work My current code is for($i=0; $i < 10; $i++) { sleep(1); echo "<tr><td style='text-align:center;'>$i</td> <td colspan=9>"; ?><input type="button" value="<?php echo $rows[$_SESSION['questions'][$i]]["question"]; ?>" onclick="location.href='game/update.php?gameID=<?php echo $player['current_game_id']."&gamequestion=".$rows[$_SESSION['questions'][$i]]["question_no"]."&runs=$runs"; ?>'"><?php echo "</td></tr>"; } NOTE that if I take sleep(1) out everything works fine but when I put it in it only gives a ten second delay after I have clicked a button that appears from in the loop. Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 1, 2012 Share Posted October 1, 2012 PHP is executed on the server. Once the script COMPLETES then the entire thing is sent to the browser. The way to achieve what you are wanting is with Javascript - not PHP. Quote Link to comment Share on other sites More sharing options...
Mahngiel Posted October 1, 2012 Share Posted October 1, 2012 I suggest you set all the elements (tr's in this case) to hidden, and use javascript and setInterval to show them. Quote Link to comment Share on other sites More sharing options...
cliftonbazaar Posted October 1, 2012 Author Share Posted October 1, 2012 (edited) Thanks for that - I'll go and search google for javascript to do this Edited October 1, 2012 by cliftonbazaar 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.