Re: populating textboxes & list boxes from database fields
| From: | Justin French | Date: | Tue, 30 Apr 2002 12:10:06 +0000 |
| Subject: | Re: populating textboxes & list boxes from database fields | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-95366@lists.php.net to get a copy of this message | ||
If you're familiar with getting data out of a table, then I don't believe
you really need any examples.
Consider the following over view or what you might do with a CD store:
Get a product row from a data base into an array. it might look something
like:
$myrow["id"] (55)
$myrow["artist"] (Nine Inch Nails)
$myrow["title"] (The downward Spiral)
$myrow["price"] (25.99)
$myrow["category"] (Alternative)
$myrow["additional_info"] (Limted edition cover art)
Apart from the category, these are all text fields, so build your form, and
echo these values into the form value="". eg:
<INPUT type="text" value="<?=$myrow["artist"]?>"
size="50" maxlength="255">
etc etc
In the case of category, you might have 5 categories in a pull down. the
aim would be to list all categories, and flag the current category as
SELECTED. This can be done with an if statement:
<SELECT name="category">
<OPTION value="rock" <? if($myrow["category"] == "rock") {
echo
"SELECTED"; } ?>>rock</OPTION>
<OPTION value="jazz" <? if($myrow["category"] == "jazz") {
echo
"SELECTED"; } ?>>jazz</OPTION>
<OPTION value="alternative" <? if($myrow["category"] ==
"alternative") {
echo "SELECTED"; } ?>>alternative</OPTION>
<OPTION value="blues" <? if($myrow["category"] == "blues") {
echo
"SELECTED"; } ?>>blues</OPTION>
</SELECT>
This would echo SELECTED in the "alternative" OPTION only.
Check boxes, groups of radio buttons, etc etc can all be done in simular
ways.
Justin French
--------------------
Creative Director
http://Indent.com.au
--------------------
on 30/04/02 9:29 PM, Denis L. Menezes (menezesd@singnet.com.sg) wrote:
> Hello friends,
>
> Can someone please tell me where I can find sample scripts for populating
> textboxes and listboxes on a form(when the form opens) using the data from
> fields in a table?
>
> Thanks
> Denis
>