I have a javascript which creates two types of elements.
The PHP code is added on submiting the form, but I show it above.
The First type looks like this:
<tr class="disc">
<span><?php echo $disc_number ?></span>.
</tr>
The Second type looks like this:
<tr class="track">
<input name="trackNumbers[]" value="<?php echo $track_number ?>" />
<input name="discNumbers[]" value="<?php echo $disc_number ?>" />
</tr>
The “track” elements can be multiple for one “disc” element.
For example:
<tr class="disc">
<span>1</span>.
</tr>
<tr class="track">
<input name="trackNumbers[]" value="1" />
<input name="discNumbers[]" value="1" />
</tr>
<tr class="track">
<input name="trackNumbers[]" value="2" />
<input name="discNumbers[]" value="1" />
</tr>
<tr class="disc">
<span>2</span>.
</tr>
<tr class="track">
<input name="trackNumbers[]" value="1" />
<input name="discNumbers[]" value="2" />
</tr>
<tr class="track">
<input name="trackNumbers[]" value="2" />
<input name="discNumbers[]" value="2" />
</tr>
To show on submit each “track” element I am using “for” command.
for ($track_i = 0; $track_i < $total_tracks; $track_i++)
But what about “disc” elements? How to make my “disc” elements to also display on submit, and to have their “track” elements after them.
If I catch your meaning correctly, you need to associate the track elements with the disc numbers… so use a multi-dimensional array:
If I recall correctly, this will produce (in PHP when submitted) an array of arrays, where each first-level array (one per disc) contains an array of tracks (one per track).