[Solved] form plugin onAfterProcess update multiple values in table

Status
Not open for further replies.

shortbow

New Member
Hi!

I'm needing a little help with the syntax...
Each time a table is edited by form, I need to update some values in another table.

I've managed to cook (based in the wiki) a way to update those values but has to execute an update command for each command, and I feel there must be a way to update all of them in one go.

So...
I'm trying to update the 4 fields of the table j_rotas with (begin_date, end_date, equip_type_id, equip_id.

I've got (working):
$query->clear();
$query->update('j_rotas')->set('equip_type_id=' . (int) $typeid )->where('id ='. (int) $id);
$myDb->setQuery($query);
$myDb->execute();

$query->clear();
$query->update('j_rotas')->set('equip_id= 99999' )->where('id='. (int) $id);
$myDb->setQuery($query);
$myDb->execute();

$query->clear();
$query->update('j_rotas')->set('begin_date= ' . $begindate)->where('id='. (int) $id);
$myDb->setQuery($query);
$myDb->execute();

$query->clear();
$query->update('j_rotas')->set('end_date= ' . $enddate)->where('id='. (int) $id);
$myDb->setQuery($query);
$myDb->execute();

how can I get them all in 1 instruction?

thanks!
 
erm... the date values updates are not working also, so any help would be apreciated... I'm guessing it needs some function to turn the variable value in the date format....
 
Can you show the code that gets your date. Although It's probably just because you didn't quote the date string.

The way to do multiple fields in an update is ...

Code:
$myDb = JFactory::getDbo);
$myQuery = $myDb->getQuery(true);
$myQuery->update('j_rotas')
   ->set('equip_type_id=' . (int) $typeid)
   ->set('equip_id = 99999' )
   ->set('begin_date= ' . $myDb->quote($begindate))
   ->set('end_date= ' . $myDb->quote($enddate))
   ->where('id='. (int) $id);
$myDb->setQuery($myQuery);
$myDb->execute();

Best to use $my on both those variables. We try to make sure your code is isolated, but there are (probably) still some places in Fabrik where you nmight clobber an existing $db or $query if you use those names.

-- hugh
 
hugh thanks a lot! that did the trick, and I will be changing the "query" name variable.

One more quick question, how do I add another condition to the query (AND).

I've tried:
$myQuery->update('j_rotas')
->set('equip_type_id=' . (int) $typeid)
->set('equip_id = 99999' )
->set('begin_date= ' . $myDb->quote($begindate))
->set('end_date= ' . $myDb->quote($enddate))
->where('id='. (int) $id)
->and('action=1');

but it did not work...
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top