By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,649 Members | 696 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,649 IT Pros & Developers. It's quick & easy.

Using a <SELECT> field on a Form

P: n/a
I have a Form with a <SELECTtab, its <OPTIONtabs generated by
records in a database table using PHP5 and a 'SELECT' query.

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'm clearly missing something very basic here.

How do I access these fields after the selection has been made and the
'Submit' button pressed?

Do I have to run another query, or is it possible to identify somehow
these related fields before post-back and pass them as $_POST variables?
Jan 2 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
..oO(Alan M Dunsmuir)
>I have a Form with a <SELECTtab, its <OPTIONtabs generated by
records in a database table using PHP5 and a 'SELECT' query.

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.
If these records are identified by a number for example, assign them to
the 'value' attribute of your select options:

<select name="foo">
<option value="1">first name</option>
<option value="2">second name</option>
...
</select>

After submit, you can find the number of the chosen option in
$_POST['foo'] or $_GET['foo'].

Micha
Jan 2 '08 #2

P: n/a
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.
Jan 2 '08 #3

P: n/a
Michael Fesser wrote:
>
If these records are identified by a number for example, assign them to
the 'value' attribute of your select options:

<select name="foo">
<option value="1">first name</option>
<option value="2">second name</option>
...
</select>
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?
Jan 2 '08 #4

P: n/a
On Wed, 02 Jan 2008 07:50:17 +0100, Alan M Dunsmuir
<al**@moonrake.demon.co.ukwrote:
Michael Fesser wrote:
> If these records are identified by a number for example, assign themto
the 'value' attribute of your select options:
<select name="foo">
<option value="1">first name</option>
<option value="2">second name</option>
...
</select>
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?
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.
--
Rik Wasmus
Jan 2 '08 #5

P: n/a
..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:

<select name="foo">
<option value="1">first name</option>
<option value="2">second name</option>
...
</select>
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
Jan 2 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.