Hi,
I'm new to PHP and MySQL, and I'm attempting to write a database for my live music collection as a first project. Currently, I have the following form and loop:
print "<form action='addtracks.php' method='post'>";
$_SESSION[no_of_discs] = $_POST[no_of_discs];
for ($disc_num=1; $disc_num <= $_SESSION[no_of_discs]; $disc_num++) {
print "<h2>Disc ".$disc_num."</h2>";
print "<input type='hidden' name='current_discnum' value='$disc_num'>";
print "<p>Number of tracks: <input type='text' name='no_of_tracks[$disc_num]' size='3' /></p>";
print "<p>Date: <input type='text' name='disc_date[$disc_num]' size='20' /></p>";
print "<p>Quality: <input type='text' name='disc_quality[$disc_num]' size='25' /></p>";
print "<p>Venue: <select name='disc_venue[$disc_num]'><option value='NONE'>Select Venue</option>";
drop_down(ID, Venue, venue, Venue);
print "</select></p>";
print "<p>Lineage: <input type='text' name='disc_lineage[$disc_num]' size='80' />";
print "<p>FLAC Fingerprints: <textarea name='disc_ffp[$disc_num]' rows='15' cols='70'></textarea>";
}
Which stores the information about each disc in the format:
no_of_tracks[$disc_num]
disc_date[$disc_num]
disc_quality[$disc_num]
disc_venue[$disc_num]
disc_lineage[$disc_num]
disc_ffp[$disc_num]
and can be accessed in addtracks.php using:
foreach($_POST['no_of_tracks'] as $item) {
print $item."<br/>";
}
But I would prefer to have it in this format instead:
$disc [$disc_num] [$no_of_tracks, $disc_date, $disc_quality, $disc_venue, $disc_lineage, $disc_ffp]
so when the results of the form are passed to addtracks.php, I could simply use a FOR loop to increment $disc_num and insert a new record for each disc in a MySQL database during each iteration of the loop. My questions are:
- How can I code the form so that the information is stored in the latter format? I'm fairly sure it needs a multidimensional array, but I'm not sure how to go about it.
- How can I then pass that array for each disc to addtracks.php and subsequently read it?
Thanks in advance for any help offered 🙂