Page 1 of 1
Row_Updating/Updated key_m loop duplicates
Posted: Sat Dec 03, 2022 2:44 pm
by konfuzion
When I loop through key_m array to insert records through my custom $sql statement
if I select 2 records it is INSERT-ing 2 times (2 loops)
if I select 3 records it is INSERT-ing 3 times (3 loops)
After testing, I realized that Row_Updating is looping 2 times already
then I also loop again through key_m which is why 2 records are duplicated and becomes 4 records.
Example
Row_Updating
//only 2 records are selected for multi-update
foreach (Post("key_m") as $key) {
$result .= $key . ","; //customer_id
//execute SQL INSERT
}
$this->setMessage("result = " . $result);
setMessage toast message shows:
result = 223,224,
result = 223,224, // duplicate loop
How can I stop looping 2 times?
Re: Row_Updating/Updated key_m loop duplicates
Posted: Sat Dec 03, 2022 3:00 pm
by konfuzion
Using the same test code above and placed in Multi-Update / PageLoad
setMessage toast message shows:
result = 223,224,
Re: Row_Updating/Updated key_m loop duplicates
Posted: Sat Dec 03, 2022 3:02 pm
by arbei
Note that Row_Updating is fired for each row.
Re: Row_Updating/Updated key_m loop duplicates
Posted: Sat Dec 03, 2022 3:27 pm
by mobhar
konfuzion wrote:
How can I stop looping 2 times?
Explode the array and process each element in its own row.
Re: Row_Updating/Updated key_m loop duplicates
Posted: Sat Dec 03, 2022 4:03 pm
by konfuzion
the $key I'm trying to individually process with SQL statement are the selected customer_id in key_m[]
Can Row_Updating / $this->customer_id->CurrentValue access the same selected records as key_m[] ? Then the foreach loop is unnecessary.
I tried removing the foreach loop and tried to use $this->customer_id->CurrentValue
but no id is showing in the setMessage popup for $this->customer_id->CurrentValue in Row_Updating
rsnew["customer_id"] doesn't work but it is unchecked and phpmaker says this field is not modifiable.
So $this->customer_id->CurrentValue is not able to work in Row_Updating? What should be used instead?
the foreach loop with $key almost worked, except it looped twice.
I'll try the explode method.
Re: Row_Updating/Updated key_m loop duplicates
Posted: Sat Dec 03, 2022 4:18 pm
by mobhar
konfuzion wrote:
rsnew["customer_id"] doesn't work but it is unchecked and phpmaker says this field is not modifiable.
Use $rsold["customer_id"]
instead.
Re: Row_Updating/Updated key_m loop duplicates
Posted: Sat Dec 03, 2022 4:36 pm
by konfuzion
what luck, that is the only one I didn't try and it's working now @_@