echo value

genesisvh
genesisvh used Ask the Experts™
on
I would like to know how to echo the value of a dropdown list with this
"<? echo $rows['county']; ?>"

Open in new window

<label for="county"></label>
          <select name="county" id="county">
            <option selected>Westchester</option>
            <option>Orange</option>
            <option>Nassau</option>
            <option>Suffolk</option>
            <option>Putnamd</option>
        </select></td>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2010

Commented:
<label for="county"></label>
          <select name="county" id="county">
            <option value="Westchester" selected>Westchester</option>
            <option value="Orange">Orange</option>
            <option value="Nassau">Nassau</option>
            <option value="Suffolk">Suffolk</option>
            <option value="Putnamd">Putnamd</option>
        </select></td>

Add value to the options and you can get the value by get or post depending on the form method..
"<? echo $_POST['county']; ?>"
"<? echo $_GET['county']; ?>"
Jagadishwor DulalSenior Web Developer

Commented:
You question is confusing if you want to display country from database to select or just want to post the country value or just want to print country dropdown ???

Author

Commented:
To post the country value.
Is this what you mean? You want that value to be selected?

<label for="county"></label>
          <select name="county" id="county">
            <option <?=($rows['county'] == 'Westchester') ? 'selected="selected"' : ''?>>Westchester</option>
            <option <?=($rows['county'] == 'Orange') ? 'selected="selected"' : ''?>>Orange</option>
            <option <?=($rows['county'] == 'Nassau') ? 'selected="selected"' : ''?>>Nassau</option>
            <option <?=($rows['county'] == 'Suffolk') ? 'selected="selected"' : ''?>>Suffolk</option>
            <option <?=($rows['county'] == 'Putnamd') ? 'selected="selected"' : ''?>>Putnamd</option>
        </select>

Open in new window

Jagadishwor DulalSenior Web Developer

Commented:
Ok Some suggestion posting here may help you:

If you are fetching record from database and want to show in drop down inside a form then:
<label for="county"></label>
          <select name="county" id="county">
<?php
//select query
//fetchrecord 
while($row=mysql_fetch_arry($var of fetchrecord)){
?>
<option value=<?php echo $row['fieldname'];?><?php echo $row['country'];?></option>
<?
}
?>

Open in new window


Will Display the record in select menu where value will be countryid or some thing you have inserted in db and country will be the name of country.

When you want to catch value of country when post form then:
<?php
$country=$_POST['country'];
?>

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial