• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Array inside array

#1
I want to get data's from 3tables (its for invoice details by customer).

Invoice Details table : https://ibb.co/WGtBkFt
Invoice Info table      : https://ibb.co/rdqwGVp
Products Info          : https://ibb.co/QPsVwY7


My code is


// Particular Customers Sales Orders
    public function particular_customers_sales_order_api(){
        $customer_id = $_POST['customer_id'];

        $invoice_details = $this->db->query("SELECT ii.invoice_no, ii.invoice_date, ii.total_igst, ii.total_cgst, ii.total_sgst, ii.invoice_sub_total, ii.invoice_discount, ii.invoice_total, ii.customer_id, ii.customer_name, ii.customer_address, ii.customer_city, ii.customer_state, ii.customer_pincode, ii.customer_phone_no, ii.customer_type, ii.customer_shipping_address, ii.customer_shipping_city, ii.customer_shipping_state, ii.customer_shipping_pincode, ii.customer_shipping_phone_no, ii.payment_mode, ii.transaction_details, ii.invoice_status FROM invoice_info ii LEFT JOIN invoice_details id ON ii.invoice_no = id.invoice_no WHERE customer_id = $customer_id GROUP BY ii.invoice_no");

        $invoice_details_array = $invoice_details->result_array();

        $invoice_no = $invoice_details_array[0]['invoice_no'];


        /*$items_list = $this->db->query("SELECT * FROM invoice_info ii JOIN invoice_details id ON ii.invoice_no = id.invoice_no JOIN products_info pi ON id.product_id = pi.product_id WHERE customer_id = $customer_id ");*/

        $items_list = $this->db->query("SELECT * FROM invoice_details id JOIN products_info pi ON id.product_id = pi.product_id WHERE invoice_no = $invoice_no");

        $num = $invoice_details->num_rows();
        //$num .= $items_list->num_rows();


        //$invoice_details_result = $invoice_details->result_array();
        $invoice_details_result = $invoice_details->result_array();
        $items_list_result = $items_list->result_array();

        //$items_list_array = array('hi'=>$items_list_result);

        $particular_customers_sales_order = array_merge($invoice_details_result,$items_list_result);

        if($num > 0){

            echo json_encode (
                    array(
                        "status"=>'true',
                        "particular_customers_sales_order"=>$particular_customers_sales_order,
                        //"1"=>$invoice_no,
                    ));
        } else {

        echo json_encode (
                    array(
                        "status"=>'false',
                        "message"=>'No Order Found',
                    ));
    }

    }



Output (current) :


{
    "status": "true",
    "particular_customers_sales_order": [
        {
            "invoice_no": "1",
            "invoice_date": "2020-01-11",
            "total_igst": null,
            "total_cgst": "126.73",
            "total_sgst": "126.73",
            "invoice_sub_total": "5069.00",
            "invoice_discount": null,
            "invoice_total": "5322.46",
            "customer_id": "1",
            "customer_name": "Ariyaputhiran",
            "customer_address": "OMR",
            "customer_city": "Vinayagapuram, Tindivanam",
            "customer_state": "Tamilnadu",
            "customer_pincode": "600121",
            "customer_phone_no": "2147483647",
            "customer_type": "general",
            "customer_shipping_address": "Vinayagapuram, Tindivanam",
            "customer_shipping_city": "Chennai",
            "customer_shipping_state": "Tamilnadu",
            "customer_shipping_pincode": "600121",
            "customer_shipping_phone_no": "2147483647",
            "payment_mode": "Online Payment",
            "transaction_details": "11832133345",
            "invoice_status": "Completed"
        },
        {
            "invoice_no": "3",
            "invoice_date": "2020-01-13",
            "total_igst": null,
            "total_cgst": "29.85",
            "total_sgst": "29.85",
            "invoice_sub_total": "1194.00",
            "invoice_discount": null,
            "invoice_total": "1253.70",
            "customer_id": "1",
            "customer_name": "Ariyaputhiran",
            "customer_address": "Vinayagapuram, Tindivanam",
            "customer_city": "Chennai",
            "customer_state": "Tamilnadu",
            "customer_pincode": "600121",
            "customer_phone_no": "2147483647",
            "customer_type": "general",
            "customer_shipping_address": "Vinayagapuram, Tindivanam",
            "customer_shipping_city": "Chennai",
            "customer_shipping_state": "Tamilnadu",
            "customer_shipping_pincode": "600121",
            "customer_shipping_phone_no": "2147483647",
            "payment_mode": "Cash on Delivery",
            "transaction_details": "Cash on Devlivery",
            "invoice_status": "Pending"
        },
        {
            "id": "1",
            "invoice_no": "1",
            "invoice_date": "2020-01-11",
            "product_id": "5",
            "seller_id": "1",
            "product_name": "Mens Checked Formal Shirt",
            "product_price": "504.00",
            "product_quantity": "1",
            "sub_total": "504.00",
            "sgst_tax": "2.50",
            "sgst_amount": "12.60",
            "cgst_tax": "2.50",
            "cgst_amount": "12.60",
            "igst_tax": null,
            "igst_amount": null,
            "total_price": "529.20",
            "product_featured_image": "stop-mens-checked-formal-shirt-01.jpg",
            "product_description": "Pick a formal style that spells freshness, simplicity and comfort with this shirt. Well-suited for regular use, this simple shirt is sure to attract a lot of admirers.",
            "product_additional_image_01": "stop-mens-checked-formal-shirt-02.jpg",
            "product_additional_image_02": "stop-mens-checked-formal-shirt-03.jpg",
            "quantity": "17",
            "original_price": "524.00",
            "sale_price": "504.00",
            "tax_percent_cgst": "2.50",
            "tax_percent_sgst": "2.50",
            "tax_percent_igst": "0.00",
            "category_id": "15",
            "category_name": "Formal Shirts",
            "seller_name": "Althaf Mannargudi",
            "is_featured": "No",
            "status": "Enable",
            "views_count": "0"
        },
        {
            "id": "2",
            "invoice_no": "1",
            "invoice_date": "2020-01-11",
            "product_id": "11",
            "seller_id": "7",
            "product_name": "Printed Men Grey Regular Shorts",
            "product_price": "625.00",
            "product_quantity": "2",
            "sub_total": "1250.00",
            "sgst_tax": "2.50",
            "sgst_amount": "31.25",
            "cgst_tax": "2.50",
            "cgst_amount": "31.25",
            "igst_tax": null,
            "igst_amount": null,
            "total_price": "1312.50",
            "product_featured_image": "jockey-printed-men-grey-regular-shorts-01.jpeg",
            "product_description": "Printed Men Grey Regular Shorts",
            "product_additional_image_01": "",
            "product_additional_image_02": "",
            "quantity": "33",
            "original_price": "649.00",
            "sale_price": "625.00",
            "tax_percent_cgst": "2.50",
            "tax_percent_sgst": "2.50",
            "tax_percent_igst": "0.00",
            "category_id": "17",
            "category_name": "Trousers",
            "seller_name": "Umapathy",
            "is_featured": "Yes",
            "status": "Enable",
            "views_count": "0"
        },
        {
            "id": "3",
            "invoice_no": "1",
            "invoice_date": "2020-01-11",
            "product_id": "15",
            "seller_id": "7",
            "product_name": "Yellow Chanderi Cotton Designer Patch Work Saree",
            "product_price": "663.00",
            "product_quantity": "5",
            "sub_total": "3315.00",
            "sgst_tax": "2.50",
            "sgst_amount": "82.88",
            "cgst_tax": "2.50",
            "cgst_amount": "82.88",
            "igst_tax": null,
            "igst_amount": null,
            "total_price": "3480.76",
            "product_featured_image": "yellow-chanderi-cotton-designer-patch-work-saree-01.jpg",
            "product_description": "Saree Fabric - Chanderi Cotton (5.5 Metres Saree)",
            "product_additional_image_01": "yellow-chanderi-cotton-designer-patch-work-saree-02.jpg",
            "product_additional_image_02": "yellow-chanderi-cotton-designer-patch-work-saree-03.jpg",
            "quantity": "94",
            "original_price": "1343.00",
            "sale_price": "663.00",
            "tax_percent_cgst": "2.50",
            "tax_percent_sgst": "2.50",
            "tax_percent_igst": "0.00",
            "category_id": "18",
            "category_name": "Banarasi Silk Designer Saree",
            "seller_name": "Umapathy",
            "is_featured": "Yes",
            "status": "Enable",
            "views_count": "0"
        }
    ]
}



But what i expect is


{
    "status": "true",
    "particular_customers_sales_order": [
        {
            "invoice_no": "1",
            "invoice_date": "2020-01-11",
            "total_igst": null,
            "total_cgst": "126.73",
            "total_sgst": "126.73",
            "invoice_sub_total": "5069.00",
            "invoice_discount": null,
            "invoice_total": "5322.46",
            "customer_id": "1",
            "customer_name": "Ariyaputhiran",
            "customer_address": "OMR",
            "customer_city": "Vinayagapuram, Tindivanam",
            "customer_state": "Tamilnadu",
            "customer_pincode": "600121",
            "customer_phone_no": "2147483647",
            "customer_type": "general",
            "customer_shipping_address": "Vinayagapuram, Tindivanam",
            "customer_shipping_city": "Chennai",
            "customer_shipping_state": "Tamilnadu",
            "customer_shipping_pincode": "600121",
            "customer_shipping_phone_no": "2147483647",
            "payment_mode": "Online Payment",
            "transaction_details": "11832133345",
            "invoice_status": "Completed",
            "line_items": [
                {
                    "id": "3",
                    "invoice_no": "1",
                    "invoice_date": "2020-01-11",
                    "product_id": "15",
                    "seller_id": "7",
                    "product_name": "Yellow Chanderi Cotton Designer Patch Work Saree",
                    "product_price": "663.00",
                    "product_quantity": "5",
                    "sub_total": "3315.00",
                    "sgst_tax": "2.50",
                    "sgst_amount": "82.88",
                    "cgst_tax": "2.50",
                    "cgst_amount": "82.88",
                    "igst_tax": null,
                    "igst_amount": null,
                    "total_price": "3480.76",
                    "product_featured_image": "yellow-chanderi-cotton-designer-patch-work-saree-01.jpg",
                    "product_description": "Saree Fabric - Chanderi Cotton (5.5 Metres Saree)",
                    "product_additional_image_01": "yellow-chanderi-cotton-designer-patch-work-saree-02.jpg",
                    "product_additional_image_02": "yellow-chanderi-cotton-designer-patch-work-saree-03.jpg",
                    "quantity": "94",
                    "original_price": "1343.00",
                    "sale_price": "663.00",
                    "tax_percent_cgst": "2.50",
                    "tax_percent_sgst": "2.50",
                    "tax_percent_igst": "0.00",
                    "category_id": "18",
                    "category_name": "Banarasi Silk Designer Saree",
                    "seller_name": "Umapathy",
                    "is_featured": "Yes",
                    "status": "Enable",
                    "views_count": "0"
                },
                {
                    "id": "1",
                    "invoice_no": "1",
                    "invoice_date": "2020-01-11",
                    "product_id": "5",
                    "seller_id": "1",
                    "product_name": "Mens Checked Formal Shirt",
                    "product_price": "504.00",
                    "product_quantity": "1",
                    "sub_total": "504.00",
                    "sgst_tax": "2.50",
                    "sgst_amount": "12.60",
                    "cgst_tax": "2.50",
                    "cgst_amount": "12.60",
                    "igst_tax": null,
                    "igst_amount": null,
                    "total_price": "529.20",
                    "product_featured_image": "stop-mens-checked-formal-shirt-01.jpg",
                    "product_description": "Pick a formal style that spells freshness, simplicity and comfort with this shirt. Well-suited for regular use, this simple shirt is sure to attract a lot of admirers.",
                    "product_additional_image_01": "stop-mens-checked-formal-shirt-02.jpg",
                    "product_additional_image_02": "stop-mens-checked-formal-shirt-03.jpg",
                    "quantity": "17",
                    "original_price": "524.00",
                    "sale_price": "504.00",
                    "tax_percent_cgst": "2.50",
                    "tax_percent_sgst": "2.50",
                    "tax_percent_igst": "0.00",
                    "category_id": "15",
                    "category_name": "Formal Shirts",
                    "seller_name": "Althaf Mannargudi",
                    "is_featured": "No",
                    "status": "Enable",
                    "views_count": "0"
                },

        },
        {
            "invoice_no": "3",
            "invoice_date": "2020-01-13",
            "total_igst": null,
            "total_cgst": "29.85",
            "total_sgst": "29.85",
            "invoice_sub_total": "1194.00",
            "invoice_discount": null,
            "invoice_total": "1253.70",
            "customer_id": "1",
            "customer_name": "Ariyaputhiran",
            "customer_address": "Vinayagapuram, Tindivanam",
            "customer_city": "Chennai",
            "customer_state": "Tamilnadu",
            "customer_pincode": "600121",
            "customer_phone_no": "2147483647",
            "customer_type": "general",
            "customer_shipping_address": "Vinayagapuram, Tindivanam",
            "customer_shipping_city": "Chennai",
            "customer_shipping_state": "Tamilnadu",
            "customer_shipping_pincode": "600121",
            "customer_shipping_phone_no": "2147483647",
            "payment_mode": "Cash on Delivery",
            "transaction_details": "Cash on Devlivery",
            "invoice_status": "Pending"
        },
        {
            "id": "2",
            "invoice_no": "1",
            "invoice_date": "2020-01-11",
            "product_id": "11",
            "seller_id": "7",
            "product_name": "Printed Men Grey Regular Shorts",
            "product_price": "625.00",
            "product_quantity": "2",
            "sub_total": "1250.00",
            "sgst_tax": "2.50",
            "sgst_amount": "31.25",
            "cgst_tax": "2.50",
            "cgst_amount": "31.25",
            "igst_tax": null,
            "igst_amount": null,
            "total_price": "1312.50",
            "product_featured_image": "jockey-printed-men-grey-regular-shorts-01.jpeg",
            "product_description": "Printed Men Grey Regular Shorts",
            "product_additional_image_01": "",
            "product_additional_image_02": "",
            "quantity": "33",
            "original_price": "649.00",
            "sale_price": "625.00",
            "tax_percent_cgst": "2.50",
            "tax_percent_sgst": "2.50",
            "tax_percent_igst": "0.00",
            "category_id": "17",
            "category_name": "Trousers",
            "seller_name": "Umapathy",
            "is_featured": "Yes",
            "status": "Enable",
            "views_count": "0"
        },
     
    ]
}
Reply

#2
i dont really get your question but if you want to make the json array you have to do json_encode
Reply

#3
i.e
{
    "status": "true",
    "particular_customers_sales_order": [
        {
          invoice_details,
          "line_items"
          [
          {
            product 01 with details,
            },
          {
            product 02 with details,
          },
            ],
            ]
}

Here's also a sample of woocommerce API which i have expect the same model, https://woocommerce.github.io/woocommerc...all-orders
Reply

#4
And in the future please use code tags for your code makes it a lot easier to read.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#5
(01-14-2020, 06:01 AM)InsiteFX Wrote: And in the future please use code tags for your code makes it a lot easier to read.


Okay any idea how to achieve it ?
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.