Populating a Drop-down List
hi
i have the following issue. i'd much appreciate someone helping me out here.
i'm trying to let a drop-down list (which will be placed, and vary on many pages) with the contents of an array. how can i get that done?
plus, once a certain element has been selected, i'd like that a link appears that links to a specific (filename with certain naming, according to the selected element) file. how could that be implmented?
again, i'd much apprecite your help
pygmalion
pygmalion
Junior Poster in Training
71 posts since Dec 2006
Reputation Points: 12
Solved Threads: 1
thanks a lot for your elaborate replies.
the populating of the drop-down list now works fine.
the case is as follows, i'm trying to populate the dropdown-list via a multidimensional array (because they will be audio recordings of parts of each chapter of a book).
now, first i'd like to declare the multi-dimensional array, which i have done as follows.
$book1 = array("chapter1" => array(),
"chapter2" => array(),
"chapter3" => array());
now, i'd like to populate the second dimension of this array by using for-loops, as follows:
$chapter1_amount = 4;
$chapter2_amount = 6;
$chapter3_amount = 8;
for($i=1; $i <= $chapter1_amount; $i++)
{
$book1["chapter1"][] = $i;
}
for($i=1; $i <= $chapter2_amount; $i++)
{
$book1["chapter2"][] = $i;
}
for($i=1; $i <= $chapter3_amount; $i++)
{
$book1["chapter3"][] = $i;
}
i think herein lies the mistake, at declaring the variables at the 2nd dimension. am i doing this correctly?
afterwards, i show the drop-down list as you guys have suggested:
echo "<select name=\"book1\"><option value=\"bleh\">Choose Part</option>";
foreach($book1 as $itemindex[] => $item[])
{
echo "<option value=\"$item\">$item</option>\n";
}
echo "</select>";
when doing it this way, i get a drop-down list which just has three identical elements, all entitled 'Array'.
once this is done, i was just wondering how i could for example manipulate a link next to it to link to a file according to the chosen element in the list.
i'd very much appreciate your help, really
pygmalion
pygmalion
Junior Poster in Training
71 posts since Dec 2006
Reputation Points: 12
Solved Threads: 1
hi again.
i'd much appreciate anyone's help. this is quite of an importance to me.
thanks in advance
pygmalion
pygmalion
Junior Poster in Training
71 posts since Dec 2006
Reputation Points: 12
Solved Threads: 1
i did everything as you said, and it worked neatly.
thanks so much, really
pygmalion
pygmalion
Junior Poster in Training
71 posts since Dec 2006
Reputation Points: 12
Solved Threads: 1