|
All the Examples on this page can be found in the php sample site
Why would we WANT to do this?
Using self populated pulldowns and multi-list boxes provides us with some increased data integrity.
- Provides improved relationships between tables w/o user intervention
- Keeps duplicates minimal
- Fast and easy (faster than typing :) )
- Helps new users who are not sure what information to put into the field
- Enforces data integrity
Some PHP code required in order to retrieve the list of Pets for the combo box and to delete:
Lets skip over the form properties since we are looking at the actual contents of the combo box itself. Click on the combo box and select HTML:
Inside the HTML tag, we see the PHP code that populates the box. Remember, we can add php code ANYWHERE HTML can be inserted, since the server interprets the php code BEFORE the browser is actually loaded.
We want to do 3 basic things
- Select the table columns to populate. In our example above, we selected the petid, petname, and the owner's nickname. We only display the petname and nickname, but the petid will be used to pass to the next page to process the activity (in this case to delete). We use the petid since it is unique with no duplicates so we don't accidentally delete the wrong pet.
- Pad the combo box with a "dummy" menu item. The echo statement can be anything. Since HTML/NOF begins incrementing with 1, but PHP begins incrementing with 0, if we did not pad in a dummy combo box menu choice, we would lose the first item retrieved.
- While there are records to be displayed, echo them to the screen. Since we are inside the combo box, they will be plugged into the combo box or multi-list box very nicely :)... cool huh?
Look and review the other combo boxes or multilist boxes to see that they are very similar in nature.
|