2 loops to insert data in my database(mysql) using reactjs(frontend) and nodejs/expressjs(backend)











up vote
0
down vote

favorite












I am stuck trying to insert 2 values in an object that has 2 arrays in it. I tried looping through the 1st object, then the 2nd, but whenever I insert the data, it only inserts the value (the second loop)at index 0 instead of inserting the value at index 0,1 and so on. For example, it would only insert the value Air Canada instead of inserting Air canada and Air Canada Rouge



Here is the code and picture below to view the JSON file in order to get a better picture of my problem (the yellow highlights in my picture are the key things to look for)



Code (React)



addClosedCRs = _ => {

this.state.jiraCLOSEDCRsAccepted.issues && Object.keys(this.state.jiraCLOSEDCRsAccepted.issues).map((issue, i) => (
this.state.jiraCLOSEDCRsAccepted.issues && this.state.jiraCLOSEDCRsAccepted.issues[i].fields && this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_11400 && Object.keys(this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_11400).map((field, customfield_11400_index) => (
fetch(`http://ca-fpscfb2:2000/ClosedCRs/add?supNumber=${this.state.jiraCLOSEDCRsAccepted.issues[i].key}&Airline=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_11400[customfield_11400_index].value}&Product=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_11600.value}&Title=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.summary}&Status=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.status.name}&DateCRRequestReceived=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.created.slice(0, 10)}&EcrNumber=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_10800}&supNumberLink=<div><a target="_blank" href="http://ksr-ca-qmaltjira.ca.kronos.com:8061/browse/${this.state.jiraCLOSEDCRsAccepted.issues[i].key}">${this.state.jiraCLOSEDCRsAccepted.issues[i].key}</a></div>`)

))
))


}

componentDidMount(){
this.addClosedCRs();
}


enter image description hereenter image description here










share|improve this question






















  • Why customfield_11600 in the fetch string ?
    – bereket gebredingle
    Nov 20 at 4:39










  • Oh its a value I am getting from the first loop to insert in my database
    – bobb1213131
    Nov 20 at 14:44










  • Any ideas why it wouldn't insert the 2nd value?
    – bobb1213131
    Nov 20 at 15:27















up vote
0
down vote

favorite












I am stuck trying to insert 2 values in an object that has 2 arrays in it. I tried looping through the 1st object, then the 2nd, but whenever I insert the data, it only inserts the value (the second loop)at index 0 instead of inserting the value at index 0,1 and so on. For example, it would only insert the value Air Canada instead of inserting Air canada and Air Canada Rouge



Here is the code and picture below to view the JSON file in order to get a better picture of my problem (the yellow highlights in my picture are the key things to look for)



Code (React)



addClosedCRs = _ => {

this.state.jiraCLOSEDCRsAccepted.issues && Object.keys(this.state.jiraCLOSEDCRsAccepted.issues).map((issue, i) => (
this.state.jiraCLOSEDCRsAccepted.issues && this.state.jiraCLOSEDCRsAccepted.issues[i].fields && this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_11400 && Object.keys(this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_11400).map((field, customfield_11400_index) => (
fetch(`http://ca-fpscfb2:2000/ClosedCRs/add?supNumber=${this.state.jiraCLOSEDCRsAccepted.issues[i].key}&Airline=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_11400[customfield_11400_index].value}&Product=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_11600.value}&Title=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.summary}&Status=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.status.name}&DateCRRequestReceived=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.created.slice(0, 10)}&EcrNumber=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_10800}&supNumberLink=<div><a target="_blank" href="http://ksr-ca-qmaltjira.ca.kronos.com:8061/browse/${this.state.jiraCLOSEDCRsAccepted.issues[i].key}">${this.state.jiraCLOSEDCRsAccepted.issues[i].key}</a></div>`)

))
))


}

componentDidMount(){
this.addClosedCRs();
}


enter image description hereenter image description here










share|improve this question






















  • Why customfield_11600 in the fetch string ?
    – bereket gebredingle
    Nov 20 at 4:39










  • Oh its a value I am getting from the first loop to insert in my database
    – bobb1213131
    Nov 20 at 14:44










  • Any ideas why it wouldn't insert the 2nd value?
    – bobb1213131
    Nov 20 at 15:27













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am stuck trying to insert 2 values in an object that has 2 arrays in it. I tried looping through the 1st object, then the 2nd, but whenever I insert the data, it only inserts the value (the second loop)at index 0 instead of inserting the value at index 0,1 and so on. For example, it would only insert the value Air Canada instead of inserting Air canada and Air Canada Rouge



Here is the code and picture below to view the JSON file in order to get a better picture of my problem (the yellow highlights in my picture are the key things to look for)



Code (React)



addClosedCRs = _ => {

this.state.jiraCLOSEDCRsAccepted.issues && Object.keys(this.state.jiraCLOSEDCRsAccepted.issues).map((issue, i) => (
this.state.jiraCLOSEDCRsAccepted.issues && this.state.jiraCLOSEDCRsAccepted.issues[i].fields && this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_11400 && Object.keys(this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_11400).map((field, customfield_11400_index) => (
fetch(`http://ca-fpscfb2:2000/ClosedCRs/add?supNumber=${this.state.jiraCLOSEDCRsAccepted.issues[i].key}&Airline=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_11400[customfield_11400_index].value}&Product=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_11600.value}&Title=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.summary}&Status=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.status.name}&DateCRRequestReceived=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.created.slice(0, 10)}&EcrNumber=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_10800}&supNumberLink=<div><a target="_blank" href="http://ksr-ca-qmaltjira.ca.kronos.com:8061/browse/${this.state.jiraCLOSEDCRsAccepted.issues[i].key}">${this.state.jiraCLOSEDCRsAccepted.issues[i].key}</a></div>`)

))
))


}

componentDidMount(){
this.addClosedCRs();
}


enter image description hereenter image description here










share|improve this question













I am stuck trying to insert 2 values in an object that has 2 arrays in it. I tried looping through the 1st object, then the 2nd, but whenever I insert the data, it only inserts the value (the second loop)at index 0 instead of inserting the value at index 0,1 and so on. For example, it would only insert the value Air Canada instead of inserting Air canada and Air Canada Rouge



Here is the code and picture below to view the JSON file in order to get a better picture of my problem (the yellow highlights in my picture are the key things to look for)



Code (React)



addClosedCRs = _ => {

this.state.jiraCLOSEDCRsAccepted.issues && Object.keys(this.state.jiraCLOSEDCRsAccepted.issues).map((issue, i) => (
this.state.jiraCLOSEDCRsAccepted.issues && this.state.jiraCLOSEDCRsAccepted.issues[i].fields && this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_11400 && Object.keys(this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_11400).map((field, customfield_11400_index) => (
fetch(`http://ca-fpscfb2:2000/ClosedCRs/add?supNumber=${this.state.jiraCLOSEDCRsAccepted.issues[i].key}&Airline=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_11400[customfield_11400_index].value}&Product=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_11600.value}&Title=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.summary}&Status=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.status.name}&DateCRRequestReceived=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.created.slice(0, 10)}&EcrNumber=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_10800}&supNumberLink=<div><a target="_blank" href="http://ksr-ca-qmaltjira.ca.kronos.com:8061/browse/${this.state.jiraCLOSEDCRsAccepted.issues[i].key}">${this.state.jiraCLOSEDCRsAccepted.issues[i].key}</a></div>`)

))
))


}

componentDidMount(){
this.addClosedCRs();
}


enter image description hereenter image description here







mysql node.js reactjs express






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 at 2:21









bobb1213131

668




668












  • Why customfield_11600 in the fetch string ?
    – bereket gebredingle
    Nov 20 at 4:39










  • Oh its a value I am getting from the first loop to insert in my database
    – bobb1213131
    Nov 20 at 14:44










  • Any ideas why it wouldn't insert the 2nd value?
    – bobb1213131
    Nov 20 at 15:27


















  • Why customfield_11600 in the fetch string ?
    – bereket gebredingle
    Nov 20 at 4:39










  • Oh its a value I am getting from the first loop to insert in my database
    – bobb1213131
    Nov 20 at 14:44










  • Any ideas why it wouldn't insert the 2nd value?
    – bobb1213131
    Nov 20 at 15:27
















Why customfield_11600 in the fetch string ?
– bereket gebredingle
Nov 20 at 4:39




Why customfield_11600 in the fetch string ?
– bereket gebredingle
Nov 20 at 4:39












Oh its a value I am getting from the first loop to insert in my database
– bobb1213131
Nov 20 at 14:44




Oh its a value I am getting from the first loop to insert in my database
– bobb1213131
Nov 20 at 14:44












Any ideas why it wouldn't insert the 2nd value?
– bobb1213131
Nov 20 at 15:27




Any ideas why it wouldn't insert the 2nd value?
– bobb1213131
Nov 20 at 15:27

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53385317%2f2-loops-to-insert-data-in-my-databasemysql-using-reactjsfrontend-and-nodejs%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53385317%2f2-loops-to-insert-data-in-my-databasemysql-using-reactjsfrontend-and-nodejs%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'