Solved

strange select problem

Posted on 2001-08-01
3
177 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now