bespokeappstt
Hubstaff freelancer
I'm trying to execute multiple update statements as there is going to be multiple selections on the element in question. The element is a dbjoin and the user can select multiple items. Using a php form plugin, the issue I am having is that only the first Update statement works. The Update statement runs for only the first value in the array. Here is the code:
So then I modified to below but now I get an error.
How do I loop through the array of values in the element and execute multiple Update statements?
Code:
// Get the db and the query
$db = JFactory::getDbo();
$query = $db->getQuery(true);
//Field to update
$field = 'available = 0';
$serialNumbers = $formModel->getElementData('rad_rentals___serial', true);
foreach ($serialNumbers as $key => $serialID)
{
//Reference column
$conditions = 'id' . '= '. $serialID ;
}//end of foreach loop
//Build SQL query and execute
$query->update($db->quoteName('rad_serialassets'))->set($field)->where($conditions);
$db->setQuery($query);
$db->execute();
So then I modified to below but now I get an error.
Code:
// Get the db and the query
$db = JFactory::getDbo();
$query = $db->getQuery(true);
//Field to update
$field = 'available = 0';
$serialNumbers = $formModel->getElementData('rad_rentals___serial', true);
foreach ($serialNumbers as $key => $serialID)
{
//Reference column
$conditions = 'id' . '= '. $serialID ;
//Build SQL query and execute
$query->update($db->quoteName('rad_serialassets'))->set($field)->where($conditions);
$db->setQuery($query);
$db->execute();
}//end of foreach loop
How do I loop through the array of values in the element and execute multiple Update statements?