last updated data as default value

hanees

New Member
I have a form with a field. I need to load last updated data to that field as default value, each time form submitted. How to do it?
 
my form got 2 fields.
1. ID
2. Name

Stored data as folows

ID Name
001 John
002 Alan
oo3 Michel

What i want is when i update a new record, the last updated data values (003 Michel) should automatically load in my form as default values in respective fields.
 
Eval'ed default of something like ...

Code:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('name')->from('yourtable')->order('id DESC)->setLimit('1');
$db->setQuery($query);
return $db->loadResult();

When you say "ID", is that the primary key of your list, or some other ID? If it's the PK, then you can't default it to anything, as it's only ever going to get a value automatically when the new record is saved.

-- hugh
 
Thanks it is working for only field. but not working for dropdown box and radio buttons. any changes in the code should be done for
those?
 
Just to explain that one ... loadResult() only loads a single field from your query (the first field of the first returned row). Which is fine for single value elements. But things like dropdowns are multiple value elements (basically any element type with the concept of 'value' and 'label' (joins, dropdowns, radios, checkbox, etc). So you need to return the array of values you want. The loadColumn() method returns an array of the first field from all returned rows.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top