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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.