|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
problem populating dropdown menu
Hi!!
I am trying to populate my dropdown menu by getting the values from the database.In this code I am trying to populate the "name" field from the table "details".I am getting a blank dropdown without any values in it. Can anybody please help me in this code. <html> <body> <?php include ("localhostconnection.php"); ?> <select name="id" style="width: 200px;"> <?php $query = mysql_query("SELECT name FROM details" ); while ($row = mysql_fetch_array($query)) { $j = mysql_num_fields($query); for($i=0;$i<$j;$i++) { $k = mysql_field_name($query,$i); $$k = $row[$k]; } print("<option value=\"$id\">$user</option>\n"); } ?> </select> </body> </html> Thankyou. |
|
#2
|
|||
|
|||
|
OK based on what I see here I would highly recommend looking through a few php tutorials. There's loads out there and they will help you understand what parts of this script do.
To give you some help to get you started though the for loop in your code is of no use at all. You just need the while loop with the print statement in it. Something like // run query // while (get a result) // print values -KM- |
|
#3
|
|||
|
|||
|
Thankyou
Hi !!
I think i was wrong in mentioning the field names and I think we need a pointer for sure which points to the each item in dropdown list.I didn't understand that.Now i got it. Anyway Thankyou so.... much |
|
#4
|
||||
|
||||
|
Where's $id being set/changed?
You could change all that PHP to read: PHP Code:
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > problem populating dropdown menu |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|