Jump to content

Recommended Posts

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.

image.png.b67fda27aaf9265445cd74c8cde752ed.png

Thanks

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/315040-php-array-from-database/
Share on other sites

@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"
    }
  ]
}

 

  1. you would write a JOIN query that gets the data that you want in the order that you want it.
  2. 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.)
  3. you would format an array of data with those keys and values
  4. 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 by mac_gyver
  • Thanks 1
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.