Skip to content
Advertisement

Get json encode data from two tables based on foreign key

I have a question for you and I have not found a solution to this, So I have two tables which are sales_details and sales_payment. Sales details where you can see all the details and the other table is for payment info/transaction. Sales details have the primary key and the sales_payment table have the FK. To combine all the data I used the inner join statement. Thanks!

Here’s an example of my data. I run a sample query using join. All of the pictures are the result of the query. I just cropped it because I can’t take a long screenshot in landscape mode.

Sales Detail Table: sales detail table

Sales Detail Table Continuation sales detail table continuation

Sales Payment Table sales payment table

As you can see, all the data in tbl_sales_payment have returned and it seems redundant. returned data

What I need is like this:

JavaScript

This what I’ve tried:

JavaScript

Advertisement

Answer

Similar code to your last question but now with the new result layout.

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement