Solved

strange select problem

Posted on 2001-08-01
3
184 Views
Last Modified: 2006-11-17
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
Comment
Question by:volvo
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
a.marsh earned 50 total points
ID: 6339527
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
 

Author Comment

by:volvo
ID: 6339565
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
 
LVL 15

Expert Comment

by:a.marsh
ID: 6339895
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question