Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

151
Vistas
Lower the variable without impact database variable

I would like to know if it is possible to lower the quantity without touching the database because here I would like the quantity variable to decrease but without updating the database. Indeed, the variable remains constant and does not reach zero if I do not update in the database with each click of the button.

Here is my code :

 db.query("SELECT * FROM articles WHERE id_article = ?",
          [[req.articleId]],
          function (err, result) {
              if (err) throw err;

              let quantity = result[0].quantite - 1;
              if (result[0].quantite < 1) {
              } else {
                  db.query("UPDATE articles SET quantite = ? WHERE id_article = ?", [quantity, req.articleId], function (err, result) { // I want to know if it's possible to make that without directly update the database...
                      if (err) throw err;
                  })

                  let token = req.headers['x-access-token'] || req.headers['authorization'] || req.cookies.token;

                  db.query("SELECT quantite FROM panier_item WHERE id_article = ? AND id_user = ?", [req.articleId, parseJwt(token).userId], function (err, result) {
                      if (err) throw err;
                      console.log(result[0])
                      if (result[0] === undefined) {
                          db.query("INSERT INTO panier_item(id_article,id_user,quantite) VALUES (?)", [[req.articleId, parseJwt(token).userId, 1]], function (err, result) {
                              if (err) throw err;
                          })
                      } else {
                          db.query("UPDATE panier_item SET quantite = ? WHERE id_article = ? AND id_user = ?", [result[0].quantite + 1, req.articleId, parseJwt(token).userId], function (err, result) {
                              if (err) throw err;
                          })
                      }
                  })
              }

Thanks you everyone,

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda