I'm building a form in a custom module, and I'd like to have that form show as it's default value the value that had been saved to the DB during the previous edit, but I have no idea how to do it.
Here is an example of one of my fields:
$form['savings_ages']['savings_age21'] = array(
'#type' => 'textfield',
'#title' => t('21'),
'#size' => 10,
'#maxlength' => 10,
'#default_value' => $whatgoeshere?,
);
My form is the basis for a calculator, so I've got over 80 fields and only ever expect to have 1 row's worth of information in my table.
I have no idea how to pull that out, so any guidance would be welcome. PLease let me know if I need to provide more detail.
EDIT: I'm still stuck on this, my normal query works when I test in the sql window of PHPmyadmin:
SELECT `factors_age21` FROM `savingfactors` WHERE 1 limit 1
but I can't seem to convert it to the correct format to work with db_query function and echo it out as the default value of my form field. PLus I'll still have to make this query 44 times (I have 44 columns) so if there is a more efficient way, I'd appreciate it.
Second Edit: I'm starting to get a partial result, but it's still wrong.
$sql = "SELECT factors_age21 FROM {savingfactors} WHERE factors_age21 LIMIT 1";
$res = db_query($sql);
$item = db_fetch_object($res);
//later
$form['savings_factors']['factors_age21'] = array(
'#type' => 'textfield',
'#title' => t('21'),
'#size' => 10,
'#maxlength' => 10,
'#default_value' => print $item,
);
It IS producing a result, but it's showing me the number "1", when my correct value is "14" any help is appreciated.
Thanks Stephanie