Using a <SELECT> field on a Form

Using a <SELECT> field on a Form

am 02.01.2008 06:29:38 von Alan M Dunsmuir

I have a Form with a tab, its

Re: Using a <SELECT> field on a Form

am 02.01.2008 07:46:09 von Alan M Dunsmuir

Alan M Dunsmuir wrote:
>
> The values displayed are chosen to be recognisable to the users (they
> are in fact a list of names), but the data I need to process in the
> post-back come from other related fields in the same database record.

I should have added in the above that I am using MySQL.

Re: Using a <SELECT> field on a Form

am 02.01.2008 07:50:17 von Alan M Dunsmuir

Michael Fesser wrote:
>
> If these records are identified by a number for example, assign them to
> the 'value' attribute of your select options:
>
>
>
I'm still missing the point here, I think.

If a user selects 'John Smith', and I know that that is the record with
value '37', how does that help me to access, say, his address and
date-of-birth without going back to the database?

Are you implying that I have to?

Re: Using a <SELECT> field on a Form

am 02.01.2008 10:12:25 von luiheidsgoeroe

On Wed, 02 Jan 2008 07:50:17 +0100, Alan M Dunsmuir =

wrote:

> Michael Fesser wrote:
>> If these records are identified by a number for example, assign them=
to
>> the 'value' attribute of your select options:
>>
>>
> I'm still missing the point here, I think.
>
> If a user selects 'John Smith', and I know that that is the record wit=
h =

> value '37', how does that help me to access, say, his address and =

> date-of-birth without going back to the database?

Short of storing the entire result in a session, or as hidden form field=
s, =

yes, you query that (again). It should have very little overhead though.=

-- =

Rik Wasmus

Re: Using a <SELECT> field on a Form

am 02.01.2008 12:08:55 von Courtney

Alan M Dunsmuir wrote:
> Michael Fesser wrote:
>>
>> If these records are identified by a number for example, assign them to
>> the 'value' attribute of your select options:
>>
>>
>>
> I'm still missing the point here, I think.
>
> If a user selects 'John Smith', and I know that that is the record with
> value '37', how does that help me to access, say, his address and
> date-of-birth without going back to the database?
>
> Are you implying that I have to?

What you can do is when you set up the form, set up a bunch of hidden
input types..

e.g.

Then if you know that the $id is 37, do

$mydob="dob_".$id;
$dob=$_POST[$mydob];

HOWEBVER since carting large amounts of data around an internet HTML
session is a huge order of magnitude slower than querying a local
database, I tend to keep data to a minimum in post variables and query
the database often instead.

Re: Using a <SELECT> field on a Form

am 02.01.2008 20:54:17 von Michael Fesser

..oO(Alan M Dunsmuir)

>Michael Fesser wrote:
>>
>> If these records are identified by a number for example, assign them to
>> the 'value' attribute of your select options:
>>
>>
>>
>I'm still missing the point here, I think.
>
>If a user selects 'John Smith', and I know that that is the record with
>value '37', how does that help me to access, say, his address and
>date-of-birth without going back to the database?

Ah, OK. Got it.

>Are you implying that I have to?

Yes, I would fetch the data directly from the DB when it's needed.

Micha

Re: Using a <SELECT> field on a Form

am 03.01.2008 11:14:40 von Toby A Inkster

Rik Wasmus wrote:

> Short of storing the entire result in a session, or as hidden form
> fields, yes, you query that (again). It should have very little overhead
> though.

Another way is to use something like this:


$data = array(
'date_of_birth' => '1980-01-01',
'name' => 'John Smith',
'address' => '123 High Street'
);
printf('',
htmlentities(serialize($data)),
htmlentities($data['name'])
);

And then once the form has been posted:

$data = unserialize($_GET['whatever']);

Don't do that unless you really trust the users though, because the $data
you get back could contain anything!

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 3 days, 21:23.]

Sharing Music with Apple iTunes
http://tobyinkster.co.uk/blog/2007/11/28/itunes-sharing/