View Single Post
Old 11-08-2012, 09:49 PM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,249
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
OH! THIS IS FUNNY!

LOOK at that code:
Code:
echo $country_options .= "<option value='" . $get_row['country'] . "'>" . $get_row['country'] . "</option>";}
Each time you add a new option to the $xxx_options, you echo it.

But what you are echoing is the FULL SET OF OPTIONS in $xxx_options!

Because the .= operator returns the CONCATENATED result, not just the part *AFTER* the operator.

You need to write something like this, instead:
Code:
$val = $get_row["country"]; // not needed, but enhances performance
if ( strpos($country_options, $val) === false )
{
    $opt = '<option value='"' . $val . '">' . $val . "</option\n";
    $country_options .= $opt;
    echo $opt;
}
HTML tags *should* use "..." for properties, not '...', which is why I changed your quoting. And the generated HTML will be easier to read and debug if you put line breaks in, as shown.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote