List select query.

This is a discussion on List select query. within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I've got a country list which, after selecting and the 'submit' button is clicked, I need for the list ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-29-2005
Richard Brooks
 
Posts: n/a
Default List select query.

I've got a country list which, after selecting and the 'submit' button
is clicked, I need for the list to re-display the selected list element,
the values are for stored database referencing only and not for display.


<select name="country">
<option value="<?php echo $country;?>" SELECTED><?php echo
$country;?></option>
<option Value="AF">Afghanistan</option>
<option Value="AL">Albania</option>
<option Value="DZ">Algeria</option>
.....
<option Value="ZW">Zimbabwe</option>
</Select>


It's one of those 'mental block' days but what I need is for the list to
display the selected element text and not the value so that the user
can check their details.

Many thanks,


Richard.

Reply With Quote
  #2 (permalink)  
Old 11-29-2005
Oli Filth
 
Posts: n/a
Default Re: List select query.

Richard Brooks wrote:
> I've got a country list which, after selecting and the 'submit' button
> is clicked, I need for the list to re-display the selected list element,
> the values are for stored database referencing only and not for display.
>
>

<...SNIP...>
>
> It's one of those 'mental block' days but what I need is for the list to
> display the selected element text and not the value so that the user
> can check their details.
>


http://www.w3.org/TR/html4/interact/forms.html#h-17.6.1

Reply With Quote
  #3 (permalink)  
Old 11-29-2005
Richard Brooks
 
Posts: n/a
Default Re: List select query.

Oli Filth wrote:
> Richard Brooks wrote:
>
>>I've got a country list which, after selecting and the 'submit' button
>>is clicked, I need for the list to re-display the selected list element,
>>the values are for stored database referencing only and not for display.
>>
>>

>
> <...SNIP...>
>
>>It's one of those 'mental block' days but what I need is for the list to
>> display the selected element text and not the value so that the user
>>can check their details.
>>

>
>
> http://www.w3.org/TR/html4/interact/forms.html#h-17.6.1


Read it through many times today and cannot find the named element I'm
looking for.

A very many thanks for your help!


Richard.

Reply With Quote
  #4 (permalink)  
Old 11-29-2005
Hilarion
 
Posts: n/a
Default Re: List select query.

> I've got a country list which, after selecting and the 'submit' button
> is clicked, I need for the list to re-display the selected list element,
> the values are for stored database referencing only and not for display.
>
>
> <select name="country">
> <option value="<?php echo $country;?>" SELECTED><?php echo
> $country;?></option>
> <option Value="AF">Afghanistan</option>
> <option Value="AL">Albania</option>
> <option Value="DZ">Algeria</option>
> ....
> <option Value="ZW">Zimbabwe</option>
> </Select>



Try this:

<select name="country">
<option Value="AF"<?php if ($country=='AF') echo ' SELECTED'; ?>>Afghanistan</option>
<option Value="AL"<?php if ($country=='AL') echo ' SELECTED'; ?>>Albania</option>
<option Value="DZ"<?php if ($country=='DZ') echo ' SELECTED'; ?>>Algeria</option>
....
<option Value="ZW"<?php if ($country=='ZW') echo ' SELECTED'; ?>>Zimbabwe</option>
</Select>

Better one, which assumes that you have your country names and codes in
some array in this format:

$countries = array(
'AF' => 'Afghanistan',
'AL' => 'Albania',
'DZ' => 'Algeria',
...
'ZW' => 'Zimbabwe'
);

would be:

<select name="country">
<?php
foreach( $countries as $code => $name )
{
printf(
"<option value=\"%s\"%s>%s</option>\n",
htmlspecialchars( $code ),
(($code === $country)?' SELECTED':''),
htmlspecialchars( $name )
);
}
?>
</select>


Hilarion
Reply With Quote
  #5 (permalink)  
Old 11-29-2005
Richard Brooks
 
Posts: n/a
Default Re: List select query.

Hilarion wrote:
>> I've got a country list which, after selecting and the 'submit' button
>> is clicked, I need for the list to re-display the selected list
>> element, the values are for stored database referencing only and not
>> for display.

[snipped]
>
> Try this:
>
> <select name="country">
> <option Value="AF"<?php if ($country=='AF') echo ' SELECTED';
> ?>>Afghanistan</option>
> <option Value="AL"<?php if ($country=='AL') echo ' SELECTED';
> ?>>Albania</option>
> <option Value="DZ"<?php if ($country=='DZ') echo ' SELECTED';
> ?>>Algeria</option>
> ....
> <option Value="ZW"<?php if ($country=='ZW') echo ' SELECTED';
> ?>>Zimbabwe</option>
> </Select>
>
> Better one, which assumes that you have your country names and codes in
> some array in this format:
>
> $countries = array(
> 'AF' => 'Afghanistan',
> 'AL' => 'Albania',
> 'DZ' => 'Algeria',
> ...
> 'ZW' => 'Zimbabwe'
> );
>
> would be:
>
> <select name="country">
> <?php
> foreach( $countries as $code => $name )
> {
> printf(
> "<option value=\"%s\"%s>%s</option>\n",
> htmlspecialchars( $code ),
> (($code === $country)?' SELECTED':''),
> htmlspecialchars( $name )
> );
> }
> ?>
> </select>
>
>
> Hilarion


Thanks Hilarion!

I've got yet another variation of the above somewhere in my archive
tonnage but I had one of those 'elderly' moments and needed a quick answer.

Thanks again!

Richard.
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 11:14 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0