Solved

strange select problem

Posted on 2001-08-01
3
188 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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 look for a specific file type in a local or remote server directory using PHP.

627 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