Inserting a data from the database to select drop down list in a table column


I am trying to insert a data from the database to select drop down list in a table where this comes in the 4th column. But it does not work. There is already data from the database to other columns and it is working , but this is not working for the 4th column in the drop down list.

How do you add this in a table column -

echo "

while ($row = mysql_fetch_array($result))
echo <option value=’". $row[‘categoryname’] ."’>". $row[‘categoryname’] ." ‘’;
echo ";

Can any one please let me know.

I don’t understand what you mean. You are trying to populate a select element from the database?

Yes , Trying to populate the data from the database to the table 4 th column. in select option .

You can see the site

Please let me know.


This is my function to do what I understand you are trying to do.
It references some other functions but I hope they are pretty obvious what they do. The essence of creating the drop down list is here.
You just call this function and then echo the result string that is returned.

function create_drop_down_box_from_mysql($table_name, $ffn, $ud, $select_name,$key_field_name, $text_field_name)
    	// This function looks up $table_name
    	// The where clause is "WHERE $ffn = '$ud'";
    	// then it loops through the returned data and builds a HTML drop down box
    	//   <SELECT name='drop_down_bom_name'>
    	//				<OPTION value='value 1' " selected">text 1</OPTION>
    	//				<OPTION value='value 2' selected>text 2 bla bla</OPTION>
    	//	 </SELECT>   	
    	$result = query_mysql_return_handle($table_name, $ffn, $ud);  // general_functions
    	$num_results = mysqli_num_rows($result);
    	// 2.  Initialise
    	$my_string = "<SELECT id='$select_name' name='$select_name'>";
    	//  3.  Loop through the results and populate
    	for($i=1; $i<=$num_results; $i++)
    		 $row = get_row_and_clean_up($result);  // strips off slashes and other non printable characters
    		 $key = $row[$key_field_name];
    		 $text = $row[$text_field_name];
    		 //print_array_recursive($row);die();  // debugging
    		 $my_string = $my_string."\n<OPTION value='$key'>$text</OPTION>";
    	$my_string = $my_string."\n</SELECT>";
    	//echo "\n<BR>$my_string"; die();
    	return $my_string;
Sponsor our Newsletter | Privacy Policy | Terms of Service