services


gallery


tutorials


process


contact


links

Gallery:  ColdFusion ASP PHP Shootout

ColdFusion

ASP

PHP

Dynamically Populating Forms

ColdFusion

When the CFOUTPUT tag is used with the QUERY attribute, code placed between the starting and ending tags is executed iteratively for all of the records in the recordset that was returned by the QUERY. Thus, for example, you would simply code a single to populate a SELECT, e.g.:

<SELECT NAME="City">
  <CFOUTPUT QUERY="GetDepartments">
    <OPTION VALUE="#GetDepartments.Location#>
      #GetDepartments.Location#
    </OPTION>
  </CFOUTPUT>
</SELECT>



ASP

Formulation of looping structures to dynamically populate forms with ASP will be dependent upon the syntax of the scripting language you choose.



PHP

Typically you’ll iterate through a set of records returned from a query with the mysql_fetch_array() function (described in" Accessing a Database") and create lines of HTML based on the results.

In situations where you might set up a series of sequentially named text fields with related data, such as employeename1, employeename2, employeename3, etc., it may prove easier both to create and process these form fields by instead coding them all with HTML to set up an array for the field, e.g.:

   <INPUT NAME="employeename[]" TYPE=TEXT>

When the form is submitted, PHP will create an array called $employeename with each element containing the value of a text box.



Copyright © 2005 Cyberglitz

email: info@cyberglitz.com