-1
Setting
I have a form and via POST send to the page preview.php
10 song names that are divided between 4 arrays. I can generate the 10 Divs containing the position array but when I create the foreach
for the artist I have a problem as he repeats the same content 10 times. How to improve this code with a smarter solution?
Code
php preview.
$track = array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
$artistname = array (
'artist1'=>$_POST['artist1'],
'artist2'=>$_POST['artist2'],
'artist3'=>$_POST['artist3'],
'artist4'=>$_POST['artist4'],
'artist5'=>$_POST['artist5'],
'artist6'=>$_POST['artist6'],
'artist7'=>$_POST['artist7'],
'artist8'=>$_POST['artist8'],
'artist9'=>$_POST['artist9'],
'artist10'=>$_POST['artist10']
);
$trackname = array (
'track1'=>$_POST['track1'],
'track2'=>$_POST['track2'],
'track3'=>$_POST['track3'],
'track4'=>$_POST['track4'],
'track5'=>$_POST['track5'],
'track6'=>$_POST['track6'],
'track7'=>$_POST['track7'],
'track8'=>$_POST['track8'],
'track9'=>$_POST['track9'],
'track10'=>$_POST['track10']
);
$recordname = array (
'record1'=>$_POST['record1'],
'record2'=>$_POST['record2'],
'record3'=>$_POST['record3'],
'record4'=>$_POST['record4'],
'record5'=>$_POST['record5'],
'record6'=>$_POST['record6'],
'record7'=>$_POST['record7'],
'record8'=>$_POST['record8'],
'record9'=>$_POST['record9'],
'record10'=>$_POST['record10']
);
<div class="row">
<div class="large-12 columns">
<h2>Confirm and submit your chart below.</h2>
<h3>September 2014 Top 10</h3>
<div class="row">
<?php for ($i = 1; $i < count($track);): ?>
<?php for($j = 0; $j < 3 && $i + $j < count($track); ++$j): ?>
<div class="large-12 columns">
<div class="row collapse prefix-radius">
<div class="small-1 columns">
<p><?php echo $track[$j + $i] ?></p>
</div>
<?php foreach($artistname as $value): ?>
<div class="small-4 columns">
<p><?php echo $value; ?></p>
</div>
<?php endforeach; ?>
<div class="small-4 columns">
<p></p>
</div>
<div class="small-3 columns">
<p></p>
</div>
</div>
</div>
<?php endfor; $i += $j;?>
<?php endfor; ?>
<div class="large-12 columns">
<input class="button" type="submit" value="Submit">
<a href="javascript:history.back();" class="button">Back</a>
</div>
</div>
</div>
</div>
And how would be the correct, 1 artist for each song? How is the association of artists with music?
– KaduAmaral
The form that sends the data is generated dynamically, ie the fields
artista1, artista2, artista3 ...
are created dynamically?– KaduAmaral