Jump to content

data entry forms generated in a loop.


matt_wood87

Recommended Posts

Hi Guys,

i'm having trouble working out the best way to do this;

 

i have an array of image names that correspond to a field in a mysql database, the number of images (array length) can vary each time the query is run. i would like to construct a form based on these images to allow me to enter other information about the pictures into the database.

 

ie. for each element in the array i want a set of input boxes, title, description, rank, that allow me to enter unique data about that specific element in the array, that i can then take and use to update my database.

 

so the page would look like

________________________

 

image0

title: *text entry box*

desc: *text entry box*

rank: *number entry box*

 

image1

title: *text entry box*

desc: *text entry box*

rank: *number entry box*

 

.

.

.

.

 

imagei

title: *text entry box*

desc: *text entry box*

rank: *number entry box*

 

 

submit button

 

any help on how i might implement this would be much appreciated!

 

Matt

Link to comment
https://forums.phpfreaks.com/topic/110828-data-entry-forms-generated-in-a-loop/
Share on other sites

thanks for the reply, but my problem isnt with iterating through the loops, its with generating a variable sized input form, here's my attempts so far that doesn't work, but hopefully should give you the gist of what i'm trying to do:

 

  function editDetails($inPhotos, $inPhotosNo) {
      $imagesDir = 'gallery/thumbs/';
      echo 'start of function<br>';
      for ($i=0; $i<$inPhotosNo; $i++){
  echo '<br>';
  ?>
  <p><img src="<?php echo $imagesDir.'/t'.$inPhotos[$i];?>"/></p>
  <form action="editarray.php" method="post">
  Title: <input type="text" name="<?php echo 'title'.$i;?>" />
  Description: <input type="text" name="<?php echo 'desc'.$i;?>" />
  Order: <input type="text" name="<?php echo 'order'.$i;?>" />
  <input type="submit" />
  </form>
  <?php
      }

 

and the editarray.php code:

 

<?php

include 'config.php';
$date = date("Y-m-d");
echo "hello";
for ($i=0;$i<3;$i++){

echo $_POST["'title'.$i"];
echo $_POST["'desc'.$i"];
echo $_POST["'order'.$i"];

}
echo "goodbye";

?>

 

all this prints out is hellogoodbye

 

thanks for looking

 

Matt

Archived

This topic is now archived and is closed to further replies.

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