Send the result of two Mysql tables to a view (ejs)

Asked

Viewed 33 times

0

I am working with Ejs and Node.JS with Mysql. I need to move to a two table info calculation view, but I am facing this error:

app.get("/calc", (req, res)=>{
    Palpite.findAll().then(calc =>{
        res.render("calc/index", {calc: calc})
    }).then(()=>{
        RPalpite.findAll().then(rp =>{
            res.render("calc/index", {rp: rp})
        })
    })
})

Error:

Referenceerror: Rp is not defined

<% rp.forEach(rpal=>{ %>
  <tr>
      <th scope="row"><%= rpal.id %></th>
      <th scope="row"><%= rpal.rp1 %></th>
      <th scope="row"><%= rpal.rp2 %></th>
      <th scope="row"><%= rpal.rp3 %></th>
      <th scope="row"><%= rpal.rp4 %></th>
      <th scope="row"><%= rpal.rp5 %></th>
  </tr>
<% }) %>
  • Hello, welcome to the O.R.! So that people can help you better, try to describe better what you have done and the result you would like to have with the code. More detailed questions help in understanding doubt.

1 answer

1

From what I understand, you want to add the two information in the template.

Here is an example of how it can be done:

app.get("/calc", (req, res)=>{
    Palpite.findAll().then(calc =>{
        req.calc = calc
    }).then(()=>{
        RPalpite.findAll().then(rp =>{
            res.render("calc/index", {rp: rp, rpal: req.calc })
        })
    })
})
  • It worked out thank you very much, excellent!!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.