1

Some background info; Over a period of in this case 5 years, i need to set a daily price, for every day of the month and for all years, since that can be different.

So i came up with this input form example

<form action="" method="POST">
   <?
   for ($years = $year; $years <= 2021; $years++) {
     ?>
     <table border="1" cellpadding="0" cellspacing="5" width="100%">
        <tr>
            <th>Year <? echo $years; ?></th>
            <td style="border:0" colspan="31"></td>
        </tr>
        <tr>
            <th>Jan</th>
            <?
            for ($i = 1; $i <= $num_days_in_jan; $i++) {
                echo '
                <td valign="top" align="left">
                    '.$i.'<p>
                    <p align="right"><input name="dayprice'.$i.'01'.$years.'" type="text" size="1" min="25" value="45"> &euro;</p>                      
                </td>';
            }
            ?>
        </tr>
        <!-- repeating for all 12 months and then all over for the next years
        ........
        ........
        -->
<?
}
?>
    </table>
    <p>
    <p align="left"><button class="w3-button w3-section w3-blue w3-ripple" type="submit" value="Complete step 6" name="action">Complete step 6</button></p>

but then i need to write some code like this to retrieve the posted data

//read data from submitted forms
if (isset($_POST['action'])){
   $action = $_POST['action'];

   if ($action == 'Complete step 6'){
      echo 'day price: '.$_POST['dayprice1012018'];
      echo 'day price: '.$_POST['dayprice2012018'];
      //.... and so on or put this is a kind of a loop



   }
 }

so i thing there must be a easy-er way of doing this of better way hope that someone can set me on a better path ... thanks guys

Marc CLH
  • 39
  • 4

1 Answers1

1

You can create array of names by adding [] to input's name attribute. For example:

<input name="dayprice['.$i.'][01]['.$years.']" type="text" size="1" min="25" value="45">

Then you can easly iterate through post variables.

symfonydevpl
  • 567
  • 1
  • 6
  • 20