Abrar Posted July 14, 2022 Share Posted July 14, 2022 Hi Friends, Hope yo all having a great day! I would like to brief my issue. Below is the API post method where i need to pass the data from my database. { "orderIncrementId": "5000003766", "items": [ { "extension_attributes": { "sku": "15882" }, "qty": 1 } ], "notify": false, "tracks": [ { "track_number": "123456", "title": "fedex Shipment", "carrier_code": "fedex" } ] For a single order number eg,. 5000003766, I may have multiple arrays SKU as below and i need to pass that in the given API. Pls assist. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/315040-php-array-from-database/ Share on other sites More sharing options...
requinix Posted July 14, 2022 Share Posted July 14, 2022 Assist with... what? What code have you written? What about it is or is not working? 1 Quote Link to comment https://forums.phpfreaks.com/topic/315040-php-array-from-database/#findComment-1598204 Share on other sites More sharing options...
Abrar Posted July 14, 2022 Author Share Posted July 14, 2022 @requinix Thanks for your quick reply. Actually i tried different codes and i am not getting a solution for it. To make it more clear I have 2 tables. - 1st table i have the order# - 2nd table i query the SKUfor that order number which may have multiple records (SKU) and i want to formulate these in an array under same order #. and pass those values in the below json format API. Could you pls assist or guide me with some code. { "orderIncrementId": "5000003766", "items": [ { "extension_attributes": { "sku": "15882" }, "qty": 1 } ], "notify": false, "tracks": [ { "track_number": "123456", "title": "fedex Shipment", "carrier_code": "fedex" } ] } Quote Link to comment https://forums.phpfreaks.com/topic/315040-php-array-from-database/#findComment-1598206 Share on other sites More sharing options...
requinix Posted July 14, 2022 Share Posted July 14, 2022 If you have problem getting your code to work then you should probably post that code. Because we'll be a lot more inclined to help if we can see what you have so far than if we had to try to do everything for you... 1 Quote Link to comment https://forums.phpfreaks.com/topic/315040-php-array-from-database/#findComment-1598224 Share on other sites More sharing options...
mac_gyver Posted July 14, 2022 Share Posted July 14, 2022 (edited) you would write a JOIN query that gets the data that you want in the order that you want it. you would build, execute, and fetch the result from that query using whatever php database extension you are using (the PDO extension is the best choice.) you would format an array of data with those keys and values you would JSON encode the array of data and output it which of these steps have you successfully completed, where are you having a problem, and what is your query/code that you need help with? what database server are you using? which php database extension are you using? do you have php's error_reporting set to E_ALL and display_errors set to ON, preferably in the php.ini on your system, so that php will help you by reporting and displaying all the errors it detects? do you have error handling for all the database statements that can fail - connection, query, prepare, and execute so that you will know if and why they are failing? using exceptions for database statement errors and in most cases simply letting php catch and handle the exception will result in database statement errors being 'automatically' displayed/logged the same as php errors. Edited July 14, 2022 by mac_gyver 1 Quote Link to comment https://forums.phpfreaks.com/topic/315040-php-array-from-database/#findComment-1598226 Share on other sites More sharing options...
Abrar Posted July 18, 2022 Author Share Posted July 18, 2022 Thank you so much @requinix & @mac_gyver The information you provided were very useful. I sorted the issue. @mac_gyver - Your steps where the best to guide me in the right direction. Thanks once again. Quote Link to comment https://forums.phpfreaks.com/topic/315040-php-array-from-database/#findComment-1598319 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.