Board index   FAQ   Search  
Register  Login
Board index php forum :: HTML HTML Basics

Select List/Menu using PHP

Discussing Html . Code , Software , other

Moderators: macek, egami, gesf

Select List/Menu using PHP

Postby Xman117 » Wed Jan 05, 2005 3:01 am

Here is my code:
<select name="country" class="sidelinks">
<?php
do
{
?>
<option value="<?php echo $row_AllCountries['country_ID']." ";?>"<?php if ($row_AllCountries['country_ID'] == $acountry) { echo "selected"; }?> >
<?php echo $row_AllCountries['countryname'];?></option>
<?php
}
while ($row_AllCountries = mysql_fetch_assoc($AllCountries));
?>
</select>

A few words to describe:
-$row_AllCountries['country_ID'](get from MySQL) is a unique country ID number
-$row_AllCountries['countryname'](get from MySQL) is the name of the country
-$acountry is the country ID number that i want to be selected when the form loads

I have a MySQL database where there are stored country names and their serial numbers(unique for each country).
I have a page with a form and there is a List Box(menu) with this countries in it.
When the page starts I want a specific country to be selected and that country ID to be equal to $acountries.
Anyone knows where's the problem and how to solve it???

Thanks and best regards
Rok
Xman117
New php-forum User
New php-forum User
 
Posts: 2
Joined: Wed Jan 05, 2005 2:57 am

Postby Oleg Butuzov » Wed Jan 05, 2005 6:12 am

just a fix
Code: Select all
<?php if ($row_AllCountries['country_ID'] == $acountry) { echo " selected "; }?>


seems that you dont have a space where it must be...
Oleg Butuzov
Last Samuray
Last Samuray
 
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Xman117 » Wed Jan 05, 2005 9:10 am

Code: Select all
<option value="<?php echo $row_AllCountries['country_ID'];?>"<?php if ($row_AllCountries['country_ID'] == $acountry) { echo " selected"; } ?> >                                   
         <?php echo $row_AllCountries['countryname'];?></option>


I was trying to solve it quite a time :))

Thnaks!!! :-?

BR
Rok
Xman117
New php-forum User
New php-forum User
 
Posts: 2
Joined: Wed Jan 05, 2005 2:57 am


Return to HTML Basics

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron