Dynamic Multiple List/Select

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kerepuki
Forum Commoner
Posts: 30
Joined: Fri Oct 29, 2004 12:28 am

Dynamic Multiple List/Select

Post 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.
User avatar
potsed
Forum Commoner
Posts: 50
Joined: Sat Oct 09, 2004 12:00 pm
Location: - South Africa

Post 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...
Post Reply