#Hi! I want to know how to return a result in my desired format.

53 messages · Page 1 of 1 (latest)

patent glacier
#

I have uploaded a pic of the desired output. Is the whole thing an array in an array? the first few outputs are from one table however the rest is from another table. How do I do this?

#

I don't know where to start with this one, are two tables being used in this one the first table is customers and the second is address where the customers address and the rest of the info is being stored. they are linked by an address id

#

I want to do a post request

sterile comet
#

whats your question?

vast matrix
patent glacier
# sterile comet whats your question?

hm i just dont know how to start coding this thing. So basically do i write an sql statement to insert all of these values into the database first and then worry about the result?

#

;~;

sterile comet
#

What values? And the result you want is that JSON object?

patent glacier
#

well basically i have two tables , the first table containing customer information like the store ID , name ,email and second table with adress information which is all of the information inside the adress array? and then i am basically using Postman to test for request and if the response is correct.

patent glacier
#

i am so sorry i am still not too familiar with backend dev so its hard for me to describe what i am doing

vast matrix
#

(I unfortunately can't help; I don't know SQL)

patent glacier
#

ooh that's ok , the object in object comment helped me know what to even start googling for

#

thanks a lot

sterile comet
#

do you just want to fill in the object with the information you have?

#

and the data you have are the "tables" are those html tables?

patent glacier
#

?

sterile comet
#

not sure what postman is, but are you trying to send the data from the tables in your frontend to your backend, put the data into your desired format, then into your database?

patent glacier
#

yes

sterile comet
#

at whatever point you want to submit the data inputted, on a frontend js page, you can get all the data from that table, put it into an object, and instead of using postman you can make a fetch to your backend.

const obj = {} // this is your table cell data in the proper format
fetch("/route", { // put whatever route youre posting to
  method: "POST",
  headers: {
    "Content-Type": "application/json"
  },
  body: JSON.stringify(obj)
})
#

in your backend im not sure if youre using express or anything

#

but you want to receive that post request, get the data from the fetch body, then upload that data into your database (im not sure how to use SQL)

patent glacier
#

oooh

#

thankyou for the help!

#

i am still new to back-end web dev

#

so im not that good with the terms

#

thanks again @sterile comet!

sterile comet
#

your welcome, are you using express for backend?

#

its a nice package its very helpful

patent glacier
#

hmm

#

i have heard a lot about php/express

#

but i honestly don't know what im using

#

im just doing what my lecturer told me

sterile comet
#

what does your backend code look like

patent glacier
#

well so there are multiple parts

#

i use vs code to do all of it

#

the first is creating a js file that connects to the database

#

it looks like this

#

and then a js file for ???

#

looks like this?

#

i think im using express

sterile comet
#

yes you are using express

patent glacier
#

O no

sterile comet
#

says it at the top

patent glacier
#

idk what im doing

sterile comet
#

require("express")

patent glacier
#

hmm sorry

#

i am actually lost on what im doing

sterile comet
#

dont want to get to off topic but if you still have questions you can ask otherwise you can close the thread