its probably a simple and rather stupid question, thousands of times asked....


i have a input box

(1surf.info,check out link)

I would like to replace it with a dropdown , again it would need to list the countries within the table. this is how it is right now,

enter state(USA) or country :<br>
<input type="text" name="name" />
<input type="submit" name="Submit" value="display" />
</form>
<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">

Recommended Answers

All 7 Replies

<form>
enter state(USA) or country :<br>
<select name="country"><option value="01">India</option>
<option value="02">Pakistan</option>
<option value="03">ShiLanka</option>
<option value="04">Dubai</option>
<option value="05">America</option>
<option value="06">England</option>
<option value="07">France</option></select>
<input type="submit" name="Submit" value="display" />
</form>
<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">


just put all the country names which you want to display as above

thanks a lot thats a good start,
wondering if this could be filled automatically from a table

cant get it running but whats wrong, the top one works but not the dropdown

<form method="post" name="display" action="display1.6.php" /> </p>
enter state(USA) or country :<br>
<input type="text" name="name" />
<input type="submit" name="Submit" value="display" />
</form>


<form method="post" name="display" action="display1.6.php" /> </p>
enter state(USA) or country :<br>
<select name="name"/>
<option value="01">India</option>
<option value="02">Pakistan</option>
<option value="03">ShiLanka</option>
<option value="04">Dubai</option>
<option value="05">America</option>
<option value="06">England</option>
<option value="07">France</option></select>
<input type="submit" name="Submit" value="display" />
</form>

<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">

<?

php code for drop down.

<?
	$sql = "select * from tbl_country";
	$res = mysql_query($sql);
	echo '<select name="country">';
	while($sar = mysql_fetch_assoc($res))
	{
		echo '<option value="'.$sar['countryId'].'">'.$sar['countryName'].'</option>';
	}
	echo '</select>';
?>
<?php
//if you already have country in youre database you can use it this way
//you dont need to write hundreds of country
$country ='';
$getcountry = mysql_query("select country_name from country_table");
while($row=mysql_fetch_array($getcountry)){
$country .='<option value="'.$row['country_name']."'>".$row['country_name']."</option>";
}
>?
<select name="country">
<option value="">Select Country</option>
<?php echo $country; ?>
</select>

or in array way

<?php
$list = array('India','Pakistan','ShiLanka','Dubai','America');
$country = '';
foreach($list as $c){
$country .='<option value="'.$c.'">'.$c.'</option>';
}
?>
<select name="country">
<option value="">Select Country</option>
<?php echo $c; ?>
</select>

you can use $country or $c variable in other form if you have other form asking for country using this

<?php echo $c; ?>

.
hope that help

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("my_db", $con);

$result = mysql_query("SELECT * FROM table_name");

while($row = mysql_fetch_array($result))
{
echo "<select name='country'><option>$row</option></select>";

}

mysql_close($con);
?>

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("my_db", $con);

$result = mysql_query("SELECT * FROM table_name");

while($row = mysql_fetch_array($result))
{
echo "<select name='country'><option>$row</option></select>";

}

mysql_close($con);
?>

while($row = mysql_fetch_array($result))
  {
//looping select element?
  echo "<select name='country'><option>$row['country']</option></select>";
  }
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.