The column names which are being taken from the database are all being added as ONE single option in the drop down menu. Where as, I want them to be separate options in the drop down menu. I don't know where am I going wrong. Please help!

The code is as follows:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Cast your vote</title>
<font size=+8>WELCOME TO THE POLL</font>
<form name="myform" action="http://localhost/project/Votingmodule/kankipadu.php" method="GET">
Select one of the following parties :</h2>
<select name="options">
//initilaize the mysql user name and password
//Database Config
$dbHost='localhost'; //Database server 
$dbName='db';  // Name of the database
$dbUser='root'; // Database username
$dbPass=''; // Database password
$source = mysql_connect($dbHost, $dbUser, $dbPass);
if (!$source) {
	die('Not connected : ' . mysql_error());
$db_selected = mysql_select_db('db', $source);
if (!$db_selected) {
	die ('Can\'t use $DB : ' . mysql_error());

$query1="select * from poll_status";

$result=mysql_query($query1) or die(mysql_error());



for($i=6;$i < $numfields; $i++)
echo mysql_field_name($result,$i) . "<br>";
<input type="submit" name="button1" value="Submit">

Recommended Answers

All 3 Replies

You cannot put the line break within the options. Perhaps, 'optgroup' is better way to use.

<optgroup label="Group 1">

for($i=6;$i < $numfields; $i++)
echo '<option value="' . mysql_field_name($result,$i) . '" name="your_option_name">';

Hope this help.

Thanks! :) That helped!

You must use
"\n" to start a new line in php out put

Which is the new line in php. <br> is break line in HTML. Both is used in different way and in different language. For example to start a new line HTML page you may output "<br>" from php.

Note: "\r\n" is carriage return and new line. To make sure the new line starts from start of the line

prasad from

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.