Jump to content

php form displaying one image per page


alexmc

Recommended Posts

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.

 

 

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.