11Tami Posted August 21, 2007 Share Posted August 21, 2007 Hi, how do I make this go from one item to the next every second? It's not liking the end of my code. Please let me know, thanks very much. <?php ini_set('error_reporting', 8191); ini_set('display_startup_errors', 1); ini_set('display_errors', 1); $a = date('s'); $maximum=10; $text[1] = "test1"; $text[2] = "test2"; $text[3] = "test3"; $text[4] = "test4"; $text[5] = "test5"; $text[6] = "test6"; $text[7] = "test7"; $text[8] = "test8"; $text[9] = "test9"; $text[10] = "test10"; $text++; while($maximum>10){$text[1];} echo "$text[a]" ?> Quote Link to comment https://forums.phpfreaks.com/topic/66015-hello-how-to-make-this-go-from-one-item-to-the-next/ Share on other sites More sharing options...
lemmin Posted August 21, 2007 Share Posted August 21, 2007 You can't increment an array like that and maximum never changes, you have to increment the index. I think you are looking for something like: for($i=0;$i<$maximum;$i++) echo $text[$i]; If you want to delay execution time, you can use the sleep() function: for($i=0;$i<$maximum;$i++) { echo $text[$i]; sleep(1); } Quote Link to comment https://forums.phpfreaks.com/topic/66015-hello-how-to-make-this-go-from-one-item-to-the-next/#findComment-330118 Share on other sites More sharing options...
11Tami Posted August 21, 2007 Author Share Posted August 21, 2007 Thanks very much, its not working, its pulling them all. I should be able to have one appear on the second, but there is no room for the $a variable in the echo, anyone know? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/66015-hello-how-to-make-this-go-from-one-item-to-the-next/#findComment-330221 Share on other sites More sharing options...
roopurt18 Posted August 21, 2007 Share Posted August 21, 2007 Are you wanting the user's browser to update a value every 1 second? Quote Link to comment https://forums.phpfreaks.com/topic/66015-hello-how-to-make-this-go-from-one-item-to-the-next/#findComment-330226 Share on other sites More sharing options...
11Tami Posted August 21, 2007 Author Share Posted August 21, 2007 Sure am, also forgot to put this right above the array, thanks. $text = Array(); <?php ini_set('error_reporting', 8191); ini_set('display_startup_errors', 1); ini_set('display_errors', 1); $a = date('s'); $maximum=10; $text = Array(); $text[1] = "test1"; $text[2] = "test2"; $text[3] = "test3"; $text[4] = "test4"; $text[5] = "test5"; $text[6] = "test6"; $text[7] = "test7"; $text[8] = "test8"; $text[9] = "test9"; $text[10] = "test10"; $text++; while($maximum>10){$text[1];} echo "$text[a]" ?> Quote Link to comment https://forums.phpfreaks.com/topic/66015-hello-how-to-make-this-go-from-one-item-to-the-next/#findComment-330238 Share on other sites More sharing options...
roopurt18 Posted August 21, 2007 Share Posted August 21, 2007 You can't use PHP to continuously update a user's browser, you'd need to use Javascript. Quote Link to comment https://forums.phpfreaks.com/topic/66015-hello-how-to-make-this-go-from-one-item-to-the-next/#findComment-330246 Share on other sites More sharing options...
11Tami Posted August 21, 2007 Author Share Posted August 21, 2007 Thanks, I'm not updating the browser, a page refresh is being done. Its to change to a new second only on the second that the page refreshes or loads. At second 1 I need it to be should be showing "testone" etc. one at a time, not all at seconds at once. <?php ini_set('error_reporting', 8191); ini_set('display_startup_errors', 1); ini_set('display_errors', 1); $a = date('s'); $maximum=10; $text = Array(); $text[1] = "testone"; $text[2] = "testtwo"; $text[3] = "testthree"; $text[4] = "testfour"; $text[5] = "testfive"; $text[6] = "testsix"; $text[7] = "testseven"; $text[8] = "testeight"; $text[9] = "testnine"; $text[10] = "testten"; $text++; for($i=0;$i<$maximum;$i++) echo $text[i].$a; ?> Quote Link to comment https://forums.phpfreaks.com/topic/66015-hello-how-to-make-this-go-from-one-item-to-the-next/#findComment-330293 Share on other sites More sharing options...
lemmin Posted August 21, 2007 Share Posted August 21, 2007 You will need to pass to your php what number it is currently on. To do this you can use the $_GET array and have the php change the javascript to "refresh" to the page adding "?num=1" (or whatever number) to the end. Quote Link to comment https://forums.phpfreaks.com/topic/66015-hello-how-to-make-this-go-from-one-item-to-the-next/#findComment-330301 Share on other sites More sharing options...
11Tami Posted August 21, 2007 Author Share Posted August 21, 2007 Thanks very much, the page is already refreshing the page another way. Can't I just get some text to show if it happens to be a certain second as long as a page is refreshing? Quote Link to comment https://forums.phpfreaks.com/topic/66015-hello-how-to-make-this-go-from-one-item-to-the-next/#findComment-330306 Share on other sites More sharing options...
lemmin Posted August 21, 2007 Share Posted August 21, 2007 Assuming you are using the system clock to determine when to change the page, theoretically you could sync the two, but not in a very efficient manner. The simplest way to do this is to change the javascript to put variable into the URL depending on the previous one. Quote Link to comment https://forums.phpfreaks.com/topic/66015-hello-how-to-make-this-go-from-one-item-to-the-next/#findComment-330310 Share on other sites More sharing options...
11Tami Posted August 21, 2007 Author Share Posted August 21, 2007 ok thanks I'll get started, if anyone knows of a way to do it similar to the above already, please let me know. Quote Link to comment https://forums.phpfreaks.com/topic/66015-hello-how-to-make-this-go-from-one-item-to-the-next/#findComment-330322 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.