Thomas_L Posted July 3, 2021 Share Posted July 3, 2021 I have a stdClass Object array with nested User arrays as a value that I would like to display in a table cell. I am struggling and have exhausted a lot of time. I am hoping to get a shove in the right direction if possible. The image below will show what I am trying to do. $someArray = json_decode($token_result); foreach ($someArray as $key => $value) { $combined[] = "<tr><td>" . $value->customer . "</td><td>" . $value->city . '</td> <td>' . $value->state . "</td><td>" . $value->zipcode . '</td> <td>' . $value->totalUsers . "</td><td>" . $value->totalActiveUsers . "</td><td>" . $value->totalInActiveUsers . '</td><td> <a href="">' . $value->users . "</a></td></tr>"; } foreach ($combined as $value) { print $value; } Here is what my Array and Objects look like Array ( [0] => stdClass Object ( [customer] => SWSH [city] => Thomasville [state] => GA [zipcode] => 31792 [totalUsers] => 6 [totalActiveUsers] => 6 [totalInActiveUsers] => 0 [users] => Array ( [0] => stdClass Object ( [firstName] => xxx [lastName] => xxx [phoneNumber] => [userName] => cb_igwrth@xxx.com [createdBy] => [isActive] => 1 ) [1] => stdClass Object ( [firstName] => Dan [lastName] => Stewart [phoneNumber] => +11111111111 [userName] => dan.sxx@xxx.ga.gov [createdBy] => kwilliams@xxx.com [isActive] => 1 ) ) ) [1] => stdClass Object ( [customer] => xxxx [city] => Carver [state] => MA [zipcode] => 02330 [totalUsers] => 3 [totalActiveUsers] => 3 [totalInActiveUsers] => 0 [users] => Array ( [0] => stdClass Object ( [firstName] => Leo [lastName] => Furtado [phoneNumber] => 781-000-0000 [userName] => LFurtado@xxx.com [createdBy] => TConger@ccccc.com [isActive] => 1 ) ) ) ) Table is attached Quote Link to comment Share on other sites More sharing options...
gw1500se Posted July 3, 2021 Share Posted July 3, 2021 It is not clear what you want displayed in that cell. Post the code you tried and tell us what is not working or what error you get. Quote Link to comment Share on other sites More sharing options...
Barand Posted July 3, 2021 Share Posted July 3, 2021 Also it would help more if you post the the json string $token_results instead of the print_r() output (which isn't processable by us) Quote Link to comment Share on other sites More sharing options...
Thomas_L Posted July 3, 2021 Author Share Posted July 3, 2021 (edited) I truly would like to loop through the user array in the current foreach loop and dump all of the values into the cell for now. After i get that working my end result will be a link that pops up a Bootstrap Modal that contains all of the user array data for each customer. Edited July 3, 2021 by Thomas_L Quote Link to comment Share on other sites More sharing options...
Barand Posted July 3, 2021 Share Posted July 3, 2021 If you just want the print-r() output (???) then '</td><td> <a href="">' . print_r($value->users, true) . "</a></td></tr>"; 1 Quote Link to comment Share on other sites More sharing options...
Thomas_L Posted July 3, 2021 Author Share Posted July 3, 2021 (edited) [{"customer":"SWSH","city":"Thomasville","state":"GA","zipcode":"31792","totalUsers":6,"totalActiveUsers":6,"totalInActiveUsers":0,"users":[{"firstName":"xxxx","lastName":"Brooks","phoneNumber":"","userName":"cb_igwrth@xxx.com","createdBy":null,"isActive":true},{"firstName":"Dan","lastName":"Stewart","phoneNumber":"+11111111111","userName":"dan.stxxt@xxxx.ga.gov","createdBy":"kwilliams@xxx.com","isActive":true},{"firstName":"Bill","lastName":"Mott","phoneNumber":"(229) 000-1231","userName":"bill@bxxxr.net","createdBy":null,"isActive":true},{"firstName":"SWSH","lastName":"Test","phoneNumber":"(229) 000-3024","userName":"swsh.test@me.com","createdBy":null,"isActive":true},{"firstName":"Cleaver","lastName":"Brooks","phoneNumber":"","userName":"cb_illngwth@xxxx.com","createdBy":null,"isActive":true},{"firstName":"Fred","lastName":"Baker","phoneNumber":"1111111111","userName":"fred.baker@xxxx.gov","createdBy":null,"isActive":true}]} As requested the Json Format Thanks for all of the help Edited July 3, 2021 by Thomas_L Quote Link to comment Share on other sites More sharing options...
Barand Posted July 3, 2021 Share Posted July 3, 2021 json_last_error_msg() says there's a syntax error when decoding the above. I shall have to scrutinize it. (I think I have a can of liquid scrute somewhere) Quote Link to comment Share on other sites More sharing options...
dodgeitorelse3 Posted July 3, 2021 Share Posted July 3, 2021 missing closing square bracket at end of Json Format Quote Link to comment Share on other sites More sharing options...
Barand Posted July 3, 2021 Share Posted July 3, 2021 (edited) 1 hour ago, dodgeitorelse3 said: missing closing square bracket at end of Json Format That's what I added, but processing it now gives $value as an array and not as an object as it was originally being processed. I get the feeling a chunk has just been copied out of the original value (as there is only a single customer) and then pasted here. I suggest that @Thomas_L writes a function to process $value->users and return whatever he wants in that column, thus... '</td><td> <a href="">' . getUserData($value->users) . "</a></td></tr>"; Example function getUserData($udata) { $res = ''; foreach ($udata as $u) { $res .= "Name : {$u['firstName']} {$u['lastName']} <br>"; } return $res; } Edited July 3, 2021 by Barand Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.