Questions and discussion about using ProcessMaker 2: user interface, running cases and functionality
Forum rules: Please search to see if a question has already been asked before posting. Please don't ask the same question in multiple forums.
By BruceBlack
#12735
I am using a GRID and I want to store the values from the grid in a database. Instead of writing each line in the grid to a separate row in the database, I tried storing the array as a single variable in the database. It seems to work fine, but I can not retrieve the data from the array again. I used the Debugger in PM, and it shows the value as an "array", but it does not show the values. I can also not see what the array looks like, so am not sure if it has any values, or what the column headers are. The only reference I can find in the WIKI, says you should write each grid row to a d-base row. My question is - is it possible to write the whole array as a single variable, and then retrieve the whole array afterwards, and then "unpack" the array again ?
User avatar
By amosbatto
#12736
Yes, it is possible to save as a single field. What you should do is use PHP's serialize() and addslashes() function to convert the grid into a string that can be saved in a database. Somthing like:
Code: Select all
$sGrid = addslashes(serialize(@=MyGrid));
$db='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; //UID for database connection
executeQuery("INSERT INTO MYTABLE (FIELD1, FIELD2) VALUES ('something', '$sGrid')", $db); 
To retrieve the stored grid and convert it from a string to a grid, use the unserialize() function. Something like:
Code: Select all
$db='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; //UID for database connection
$result = executeQuery("SELECT * FROM MYTABLE WHERE FIELD1='something'", $db);
if (is_array($result) and count($result) > 0)
   @=SomeGrid = unserialize($result[1]['FIELD2']);
I haven't tried this code yet, so test it for me. If it works, then I will add it to the wiki.
By BruceBlack
#12738
Code works perfectly !!! Can write and read.

Thanks a lot for the fast reply

I have not added the $db part - as I am using Process Maker tables, but it's perfect.
By mamad71
#825679
Hi amos
I test your solution but it wont insert any data into db when i have a Grid with a Dropdown inside it
When i print the data of $sGrid with die($sGrid) it show me this :
Code: Select all
a:1:{i:1;a:2:{s:18:\"dropdown0000000001\";s:3:\"123\";s:24:\"dropdown0000000001_label\";s:8:\"12345678\";}}
This is for the case that i only insert one dropdown into grid with key=123 and value=12345678
Inserting this string into a varchar field of a pmt table actually wont insert any thing into that table.

In another case i insert two dropdown into Grid.i select 12345678 from the first dropdown and 87654321 from the second.
This is the result of die($sGrid):
Code: Select all
a:2:{i:1;a:2:{s:18:\"dropdown0000000001\";s:3:\"123\";s:24:\"dropdown0000000001_label\";s:8:\"12345678\";}i:2;a:2:{s:18:\"dropdown0000000001\";s:6:\"123456\";s:24:\"dropdown0000000001_label\";s:8:\"87654321\";}}
User avatar
By amosbatto
#825767
mamad71 wrote:I test your solution but it wont insert any data into db when i have a Grid with a Dropdown inside it
When i print the data of $sGrid with die($sGrid) it show me this :
Try it with json_encode() and json_decode():
Code: Select all
$sGrid = addslashes(json_encode(@=MyGrid));
$db='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; //UID for database connection
executeQuery("INSERT INTO MYTABLE (FIELD1, FIELD2) VALUES ('something', '$sGrid')", $db); 
To retrieve the stored grid and convert it from a string to a grid, use the json_decode() function. Something like:
Code: Select all
$db='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; //UID for database connection
$result = executeQuery("SELECT * FROM MYTABLE WHERE FIELD1='something'", $db);
if (is_array($result) and count($result) > 0)
   @=SomeGrid = json_decode($result[1]['FIELD2']);
Does that work?

A 1xbet clone script is a pre-designed software so[…]

4rabet clone script is enabling entrepreneurs to e[…]

Parimatch clone script is enabling entrepreneurs t[…]

In the world of cryptocurrency, a wallet is an app[…]