Page 1 of 1

Dynamic Multiple List/Select

Posted: Fri Nov 19, 2004 7:52 pm
by kerepuki
I will try to explain as best I can what I am trying to do.

OK...I have 3 tables, stationery_items, stationery_details, student_year.

I have a page that displays the student year and the stationery items, both dynamic tables.

What I would like from here is the user be able to select a student year from a combo box, possibly have them be able to select more then one, and also select the stationery items, and the quantity required, more then one.

When this is submitted the stationery_details table will store the student year (say year 7) and the items selected (say Red Pen, Blue Pen, 1B4 Book)

What would be the best and easiest way of doing this. I am creating the site in Dreamweaver and I dont really have a lot of coding experience, but I could manage if need be.

Posted: Sat Nov 20, 2004 7:28 am
by potsed
The best way to do this is with a database (mySql) in which you will be able to store the items and the students, then you would need to interact with the database using a php script, which would also be able to dynamically create the form you would need...

for example using php to build the combo box for student years Could be done somthing like:

Code: Select all

<?php
$date = date("Y"); // get the current year
$yearsToShow = 15; // number of year to show in list
$select = '<select id="studentYear">'."\r\n"; // output select code
//loop for building list
for($i=-2;$i<$yearsToShow;$i++)&#123;
    $curYear = $date + $i; // calculate the next entry date

    //if the next entry date is = to this year make it the default selection
    $selected = ($curYear === $date) ? 'selected' : '';

    //add the option to the list
    $select .= '<option value="'.$curYear.'" '.$selected.'>'.$curYear.'</option>'."\r\n";
&#125;

// close the list
$select .= '</select>'."\r\n";

// write the list on the page
echo $select;
save as date.php to test...