Is there a trick to being able to use the Merge function with array elements, or do I have to pull the data out of each element and put it into a variable before merging?
I looked around in the forums, but was unable to find anything.
Here is the merge I am trying to do:
the elements of $_POST are:
$_POST["system_uid"] = TESTING
$_POST["name"] = TEST ID
$_POST["system_id"] = TESTSYSTEM
$_POST["mgr_ldap_uid"] = 1234567
INSERT INTO idmap_systems (system_uid, name, system_id, mgr_ldap_uid) VALUES ('[[$_POST["system_uid"]]]','[[$_POST["name"]]]','[[$_POST["system_id"]]]','[[$_POST["mgr_ldap_uid"]]]')
And, of course, I am ending up with
INSERT INTO idmap_systems (system_uid, name, system_id, mgr_ldap_uid) VALUES (']',']',']',']')
I'm going to go ahead and just pull the elements out into variables, so this is more curiosity/a chance to learn than anything else. I mean, it totally makes sense that this would not work because of the use of square brackets by both, but I would be surprised if there were not some way to directly use the elements of an array with merge.
Using Merge function with arrays
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Using Merge function with arrays
I came across this a long time ago using some templates I made for a project with on-rev server. From memory I think the answer is simply to add an extra square bracket either side (so you have triple brackets) but for the life of me I can't remember for certain. I will be able to check when I get home but that won't be for 10 hours or more.
Re: Using Merge function with arrays
Figured it out - put parentheses around the array reference and it all works just fine. So:
INSERT INTO idmap_systems (system_uid, name, system_id, mgr_ldap_uid) VALUES ('[[($_POST["system_uid"])]]','[[($_POST["name"])]]','[[($_POST["system_id"])]]','[[($_POST["mgr_ldap_uid"])]]')
is the correct template text for my issue.
Hopefully this helps someone out there down the line. I guess I should probably file a bug report on the docs to get this added as well.
INSERT INTO idmap_systems (system_uid, name, system_id, mgr_ldap_uid) VALUES ('[[($_POST["system_uid"])]]','[[($_POST["name"])]]','[[($_POST["system_id"])]]','[[($_POST["mgr_ldap_uid"])]]')
is the correct template text for my issue.
Hopefully this helps someone out there down the line. I guess I should probably file a bug report on the docs to get this added as well.
Last edited by edgore on Sat Oct 12, 2013 12:20 am, edited 1 time in total.
Re: Using Merge function with arrays
Hi Ed, just got home (earlier than anticipated) and the way I discovered is to put an extra space between the closing square bracket and the merge pair, ie so in this case the value merges to the sListingA['close_deal'] array element. Seems like parentheses is a more intuitive way to ensure the right result. Glad it's working.
Code: Select all
value='[[sListingA['close_deal'] ]]'