Webform component weight within a Fieldset I am creating a settings page for a specific Webform in version 6.x-3.x which finds all select option components in the form and creates a numeric textfield setting correlating to each select option. The Select Options are in fieldsets. On the settings page, I want the numeric textfields to show up in the same order that the select options show up in the form.

db_querying the right select options in the webform_component table is working fine, but the select options show up out of order when ordering by weight.

For example:

The Webform

Fieldset 1
- Textfield 1
- Select Option 1
- Select Option 2
Fieldset 2
- Select Option 3
- Select Option 4


db_query('SELECT * FROM drupal_webform_component WHERE TYPE = "select" AND nid=123 ORDER BY weight'); generates results like this:

Select Option 1
Select Option 3
Select Option 4
Select Option 2


How do I order Webform results of components within fieldsets to reflect the order they appear on the form? What would the db_query look like?
Ok, there is a column pid in webform_components for individual components. This value correlates with the cid of the fieldset. A LEFT OUTER JOIN between the cid and pid columns, filtered by the webform node id - nid, then ordered by the fieldset weight followed by the select option weight returns the components in the correct order as they appear on the node form. Here is the db_query statement.

db_query('SELECT *
FROM webform_component AS f
LEFT OUTER JOIN webform_component AS s ON f.cid = s.pid
WHERE f.nid = 123 AND s.nid = 123 AND f.type = "fieldset" AND s.type = "select"
ORDER BY f.weight, s.weight');


This works. Any advice on optimizing this query is appreciated.