Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
By Marvin
#825837
Hello,

I have a grid named GDOrder used to record Sales, where:
Qty | Desc | Price

I need to copy it to another grid say, ITEMDesc where for each item a unique identification code needs to be inserted.

Example - GDOrder
2 Laptop $3,000
3 Printer $1,500

Item is expanded in ITEMDesc
# | Desc | Price | UID
Row1 Laptop $3,000 xxxx-xxxx-xxxx
Row2 Laptop $3,000 xxxx-xxxx-xxxx
Row3 Printer $1,500 xxxx-xxxx-xxxx
Row4 Printer $1,500 xxxx-xxxx-xxxx
Row5 Printer $1,500 xxxx-xxxx-xxxx

Help much appreciated.
User avatar
By amosbatto
#825874
You didn't explain how the unique ID numbers are being obtained, so I will give you an example using auto-incrementing IDs:
Code: Select all
@=ITEMDesc = array(); //create an empty grid

if (is_array(@=GDOrder)) {
   $rowNo = 1;
   $id = rand(0, 1000);

   foreach (@=GDOrder as $aOrder) {
      $quantity = $aOrder['Qty'];

      for ($i=1; $i <= $quantity; $i++) {
           @=ITEMDesc[ $rowNo ] = array(
              "No" => $rowNo,
              "Desc" => $aOrder['Desc'],
              "Price" => $aOrder['Price'],
              "UID" => $id + $rowNo 
           );
           $rowNo++;
      }
   }        
}
Make sure that the grid variables and the IDs in the grid fields are spelled exactly as listed in the above code.
By Marvin
#825889
Dear Sir Amosbatto,

You are a legend. It works!!! Thanks.

I just removed the auto-generating ID since the keys are actually provided by outside suppliers.
I shall keep it in mind for future use.

Get an instant solution to move emails to MBOX for[…]

Most Demanding OST to PST Converter

The most demanding OST to PST Converter is TrijaT[…]

Betvisa clone scripts are pre-built software solut[…]

A Bet365 Clone Script is essentially a ready-made […]