0

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

4
Contributors
7
Replies
9
Views
6 Years
Discussion Span
Last Post by happytogether
0

<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

0

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

0

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

<?

0

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>';
?>
0
<?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

Edited by happytogether: n/a

-1

<?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);
?>

0

<?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>";
  }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.