Jump to content

Autopopulating a Drop down list


prcollin

Recommended Posts

I have an option on a form that is a drop down, I want it to auto populate with the current clients in the database.

 

So basically everytime the form is called i want it to read my database and let me choose from any current client in the database on a name basis.

 

I know how to make a list and drop down menu i dotn know how to auto populate it with the current names in a cllumn of my db though.  Any help?

Link to comment
https://forums.phpfreaks.com/topic/115904-autopopulating-a-drop-down-list/
Share on other sites

<?php
//this code is bringing in the values for dropdown number 1.
$query="SELECT * FROM CHANGETOTABLE";

/* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */
$result = mysql_query ($query);
echo "<option><select name=\"CHANGETOTABLE\" value='1'>CHANGEcity</option>";
// printing the list box select command

while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
	echo "<option value=\"$nt[VALUEOFOPTION]\">$nt[DISPLAYOFOPTION]</option>";
	/* Option values are added by looping through the array */
	}
echo "</select>";// Closing of list box

?>

 

Change a few things in that code and it will select the info from the database.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.