I'm trying to update form values based on records retrieved from a db_select. The code shown below works functionally, but I'm concerned about the methods I'm using to the reference the record and wondering if there isn't a more elegant solution so that I don't have to reference the record in question by record number and can instead use the fieldid, which is the primary key for each record.
function get_v01_fielddata ($entry = array()) {
// Read all fields from the v01fielddata table.
$select = db_select('v01fielddata', 'v');
$select->fields('v');
return $select->execute()->fetchAll();
}
function tactix_lit_v01_fields ($form, &$form_submit) {
$entries = get_v01_fielddata();
debug($entries);
$form['v01_price'] = array (
'#title' => $entries[4]->title_default,
'#type' => 'textfield',
'#default_value' => $entries[4]->value_default,
'#field_prefix' => t('$'),
'#maxlength' => 25,
'#size' => 20,
'#description' => $entries[4]->desc_default,
);
This is a sample of the data that is being return using $debug(entries). I'm actually referencing record #4 in the returned data set... I'm showing only the first two. The records seem to be returned in alphabetical order based on fieldid.
array (
0 =>
stdClass::__set_state(array(
'fieldid' => 'v01downpay',