For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > December 2004 > Re: [PHP-DB] Filling Drop-Down Box.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [PHP-DB] Filling Drop-Down Box.
Mike S.

2004-12-27, 3:55 pm

> Hello All,
>
> I want to fill drop-down box from mysql table, if any body
> be kind to tell me a sample code :)
> e.g:
> In my application i want to gather subject list from current
> semester-subject table of a student.
>
> TIA
> --
> Nayyar Ahmad


You know that the HTML code for the drop-down is:
<SELECT NAME="SAMPLE">
<OPTION VALUE="1">Whatever 1</OPTION>
<OPTION VALUE="2">Whatever 2</OPTION>
</SELECT>

Here's some "pseudo-code" remarks that should help you with your coding:

------------- whatever.html -------------
Drop-down: <SELECT NAME="sample">
<?php
// connect to your database - if you haven't already
// construct a query to pull the records you want, and
// in the order you want to display them
// execute the query
// loop through the results, building an <OPTION>whatever</OPTION>
// for each element in the drop-down. You can get creative
// here if you need to. Like:
// <OPTION VALUE="##">whatever</OPTION>
// where ## is the key field, and whatever is another
// (descriptive) field in your query
// close your database connection (or later, if needed)
?></SELECT>

Try to fill in the actual code yourself.
If you get stuck, you can look at:
http://www.netmask.com/php-db/sample-dropdown.html

Good luck!

:Mike S.
:Austin TX USA
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com