If I understand you correctly, here is my approach in php:

You look at the selected value first and store it in idSelected;
then you insert a condition and evaluate that condition in your
printf statement:

>    while ($row = mysql_fetch_object ($list)) {
           $selected = $row->id == $idSelected ? 'selected' : '';
      printf("<OPTION VALUE=%s %s>%s</OPTION>", $row->id, $selected, $row->type);
>    }

BTW, I use a class for form element handling, so the whole stuff
is automated and looks like that in my form setup (example taken
from a form to gather horse data):

$elForm[] = stdSelect("breed", "", $options, $data[breed]);

$elForm holds all form elements, stdSelect is a member function
of the select class, itself a subclass of the element class. It
is defined as

function stdSelect($name, $label="", $options, $value="", $size=1){
         ... easy stuff, just feed the defining array
}

$option, of course, is an array holding the data, which has to be
built like you do with a while loop:

        while($db->next_record()){
                $options[] = $db->f('nameBreed');
        }

This in turn makes use of the lingo of PHPLIB. It may not look
like big stuff, but it is easier to write and handle and
therefore easier to think of and about and less errorprone. So in
the long run, it pays big to work with well defined classes.

The class handles all necessary stuff as composing the html code,
checking validity fo data and the like. No direct contact with
html at all.

I don't recommend this class, though, as it is an old one which is
not really good, there are better ones on the market, I'm sure.

You may have a look at http://phpclasses.upperdesign.com for
newer and better classes, there are plenty by now. There even
maybe one in PEAR - that would be a good project, at least.

-- 
Herzlich
Werner Stuerenburg            

_________________________________________________
ISIS Verlag, Teut 3, D-32683 Barntrup-Alverdissen
Tel 0(049) 5224-997 407 · Fax 0(049) 5224-997 409
http://pferdezeitung.de



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to