alexmc Posted July 15, 2007 Share Posted July 15, 2007 Hello. I'm sorry - I am very new to PHP and I have become incredibly stuck on something.. Maybe someone can show me the light (I think I am missing the obvious now). I have a file images.txt ... with a list of images. I put this into an array, and then randomize the array with shuffle (want it randomized for each user) Then I use "foreach" or something similar to loop through that file. Foreach of these images I generate html for a FORM showing this image (<img src=<? echo $image; ?>>) with a text box underneath (name="image name") and .. at the end a submit button that submits the input to another .php file for processsing (puts into file in this case). .... all that is fine, with all the images on ONE page. However, I would like each form (with each image) to be presented ONE AT A TIME and not to move on to next one until the submit button has been pressed and the data submitted (it should be one "page" per image). Everything I have tried either puts all the pics on one page, or reloads the page. How would you do this!? Thanks a lot. Quote Link to comment Share on other sites More sharing options...
pedrobcabral Posted July 15, 2007 Share Posted July 15, 2007 Remove the loop and keep the code to get the img src. Then it might display just one. When refreshing the page it will probably get an other random picture. Quote Link to comment Share on other sites More sharing options...
alexmc Posted July 15, 2007 Author Share Posted July 15, 2007 Thanks for the reply. Problem is I don't want any images to be repeated. I could just take out the loop and let it present one image - submit the form and tell it to reload the page and it starts again - gets another random image ...... however, what method could I use here to REMOVE an image once it is seen when I'm not in a loop? I want the user to see each image once and then exit - so I was using an array (to read in images.txt- list of image names) and a foreach loop (or taking away the first element of the array until empty). Thanks. Quote Link to comment Share on other sites More sharing options...
pedrobcabral Posted July 15, 2007 Share Posted July 15, 2007 You could add the ID's from arrays to a session so you could check if already exists and run the function again. But this sounds as a not straight-to-the-point solution. But I can't think of nothing else, hope anyone there can give you a better solution. Quote Link to comment Share on other sites More sharing options...
pyrodude Posted July 15, 2007 Share Posted July 15, 2007 Actually, that should work. use count() to count the number of lines in images.txt, then use rand(1,$resultfromcount) to fgets that line. Then, store something in $_SESSION['file'][$linenumber] Then, before it reads sends any values to the screen, it checks isset($_SESSION['file'][$linenumber] You would, of course, need a counter so that you don't wind up in an infinite loop, but that would be simple enough... Quote Link to comment Share on other sites More sharing options...
felixx68 Posted July 15, 2007 Share Posted July 15, 2007 Couldn't you just unset each image variable from within the loop? ??? Josh Quote Link to comment Share on other sites More sharing options...
alexmc Posted July 15, 2007 Author Share Posted July 15, 2007 Thanks for replies. Yes, I think using SESSION sounds good! I was a bit caught up on using the loop. In response to felixx68 - yes, this is what I did with the loop - the problem was that I couldn't use the loop and do what I wanted... as I have to reload the page. Thanks. 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.