PHP-Sandbox - PHP script help - support array in array #562
Answered
by
sam8881998
sam8881998
asked this question in
Q&A
-
Dear all, Please help. Millions thanks. json file { PHP Script: getConnection('ConnectMysqltrackandtraceDB'); $payload = $request->getPayload(); $id = $request->get('id'); // returns a path or query parameter $arguments = $request->getArguments(); // returns all available arguments as array $user = $context ->getUser(); if ($user !== null) { // User is authenticated, you can access user properties $userId = $user->getname(); // Access more user properties as needed } else { // User is not authenticated // Handle the case when no user is authenticated } if ($payload->get('details') != null) { foreach ($payload->get('details') as $item) { $connection->insert('tt_db.test_items', [ 'number' => $item->get('number'), 'name' => $item->get('name'), 'user' => $userId, ]); foreach ($payload->get('items') as $title) { $connection->insert('tt_db.test_items', [ 'title' => $title->get('number'), ]); }} } return $response->build(200, [], [ 'id' => $id, 'uriFragments' => $arguments, 'payload' => $payload, ]); ------- |
Beta Was this translation helpful? Give feedback.
Answered by
sam8881998
Jul 19, 2024
Replies: 1 comment 3 replies
-
Hi @sam8881998 could you format the PHP code by adding ```php at the start and ``` at the end of your code block |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dear Chris,
Thank you so much for your reply.
I tested and if the json file is changed to below, and I need to store the record like:
Table structure: Autonumber (managed by database automatically), Number, Name, Title
I would like to have the below Stored Table Data result:
10001, 50,Name 50, Null
10002, 2,Name 2, manager
10003, 2,Name 2, Student
10004, 1000,Name 1000, department head
10005, 1000,Name 1000, Supervisor
I changed a little bit coding (I was adding the indicator but still not working and below is the latest version) but get two Null records for name 2 and Name 1000.
Would you please provide guidance how to get the above expected result and thanks in advance.
Samuel
Json file:
{