Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

strange select problem

Hello

I have a select statement like this:

echo "<Select name=sel_column>";
   $result2 = mysql_query("select distinct column from $tablename");
   while ($row2=mysql_fetch_array($result2)) {
      if ($row2[column]==$row[$a_column[0]]) {
         echo "<option selected value=".$row2[column].">".$row2[column]."</option>";
      }
      else {
     echo "<option size=100>".$row2[column]."</option>";
     }
   }
echo "</select>";

The values in the select statement are strings of 3 words, looks like this:

'books papers magazines'

when i change the select statement and post it the $sel_column gives me the good value 'books papers magazines'

when i change something else in the form and not the select statement an i post the form the $sel_column gives me the value 'books'

Why ????


0
volvo
Asked:
volvo
  • 2
1 Solution
 
a.marshCommented:
Your code seems a little inconsistent....you don't always set the value attribute of the <option> tag...is there a reason for that??

If you do set the value and that value has spaces in it you should use quotes e.g. change:

echo "<option selected value=".$row2[column].">".$row2[column]."</option>";

to:

echo "<option selected value=\"".$row2[column]."\">".$row2[column]."</option>";


And what do you expect this to do:

option size=100

???



Ant
0
 
volvoAuthor Commented:
Hello A.marsh

this works fine :echo "<option selected value=\"".$row2[column]."\">".$row2[column]."</option>";

Thanks.

This form need to make it possible that users can change there settings.

So i set the selected value on the value that is stored in de user Data Base for a specified user.


option size=100: this was just a test.  I trie to set the size for the option.  Is that not possible???

It is not nice that the option has not the same size as the input opbject.
0
 
a.marshCommented:
To do that you need to use this (but it doesn't work on all browsers):

<input type="text" style="width: 100px">

<select style="width: 100px">


Glad I could help.

Now that you have the solution to your problem, please feel free to accept my earlier comment as the answer in order to wrap this question up.

:o)

Ant
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now