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












0















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 '18 at 4:39











  • Oh its a value I am getting from the first loop to insert in my database

    – bobb1213131
    Nov 20 '18 at 14:44











  • Any ideas why it wouldn't insert the 2nd value?

    – bobb1213131
    Nov 20 '18 at 15:27
















0















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 '18 at 4:39











  • Oh its a value I am getting from the first loop to insert in my database

    – bobb1213131
    Nov 20 '18 at 14:44











  • Any ideas why it wouldn't insert the 2nd value?

    – bobb1213131
    Nov 20 '18 at 15:27














0












0








0








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 '18 at 2:21









bobb1213131bobb1213131

728




728













  • Why customfield_11600 in the fetch string ?

    – bereket gebredingle
    Nov 20 '18 at 4:39











  • Oh its a value I am getting from the first loop to insert in my database

    – bobb1213131
    Nov 20 '18 at 14:44











  • Any ideas why it wouldn't insert the 2nd value?

    – bobb1213131
    Nov 20 '18 at 15:27



















  • Why customfield_11600 in the fetch string ?

    – bereket gebredingle
    Nov 20 '18 at 4:39











  • Oh its a value I am getting from the first loop to insert in my database

    – bobb1213131
    Nov 20 '18 at 14:44











  • Any ideas why it wouldn't insert the 2nd value?

    – bobb1213131
    Nov 20 '18 at 15:27

















Why customfield_11600 in the fetch string ?

– bereket gebredingle
Nov 20 '18 at 4:39





Why customfield_11600 in the fetch string ?

– bereket gebredingle
Nov 20 '18 at 4:39













Oh its a value I am getting from the first loop to insert in my database

– bobb1213131
Nov 20 '18 at 14:44





Oh its a value I am getting from the first loop to insert in my database

– bobb1213131
Nov 20 '18 at 14:44













Any ideas why it wouldn't insert the 2nd value?

– bobb1213131
Nov 20 '18 at 15:27





Any ideas why it wouldn't insert the 2nd value?

– bobb1213131
Nov 20 '18 at 15:27












0






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',
autoActivateHeartbeat: false,
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

























0






active

oldest

votes








0






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.




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

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents