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">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Cast your vote</title>
</head>
<body>
<center>
<font size=+8>WELCOME TO THE POLL</font>
<hr>
<br>
<br>
<br>
<br>
<center>
<form name="myform" action="http://localhost/project/Votingmodule/kankipadu.php" method="GET">
<h2>
Select one of the following parties :</h2>
<br>
<center>
<select name="options">
<option>B.J.P</option>
<option>Congress(I)</option>
<option>C.P.I(M)</option>
<option>
<?php
//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());

$numfields=mysql_num_fields($result);

$i=0;

for($i=6;$i < $numfields; $i++)
{
echo mysql_field_name($result,$i) . "<br>";
}
?>
</option>
</select>
<br><br>
<br>
<br>
<br>
<center>
<input type="submit" name="button1" value="Submit">
</center>
</form>

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

<optgroup label="Group 1">
$i=0;

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

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
http://365greetings.com

Be a part of the DaniWeb community

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