Solved

strange select problem

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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…
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 …

911 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

20 Experts available now in Live!

Get 1:1 Help Now