Row_Updating/Updated key_m loop duplicates

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
konfuzion
User
Posts: 378

Row_Updating/Updated key_m loop duplicates

Post 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?


konfuzion
User
Posts: 378

Post by konfuzion »

Using the same test code above and placed in Multi-Update / PageLoad

setMessage toast message shows:
result = 223,224,


arbei
User
Posts: 9286

Post by arbei »

Note that Row_Updating is fired for each row.


mobhar
User
Posts: 11660

Post by mobhar »

konfuzion wrote:

How can I stop looping 2 times?

Explode the array and process each element in its own row.


konfuzion
User
Posts: 378

Post 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.


mobhar
User
Posts: 11660

Post 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.


konfuzion
User
Posts: 378

Post by konfuzion »

what luck, that is the only one I didn't try and it's working now @_@


Post Reply