Monday, 22 May 2017

printing users rows on webpage using node.js and my sql

I working on a code to printing users email row on webpage if users have a certain value on some row using node.js and my sql

so I created this code I get the right values when I run it on console.log but when I tried it with res.send(); I get this error

Error: Can't set headers after they are sent.

and just get one row not all users rows

I tried to write return after my res.send and that's give me only one row how I can get all row on the webpage ?

app.get('/usersrooms', function (req, res, next) {
    var userslist = "SELECT * FROM users ORDER BY id";    
    var query = connection.query(userslist, function(err,rows, result) {

    if (rows.length > 0) {
        for (var i in rows) {


            if (rows[i].onmatch == 0){
                //console.log("the mails",rows[i].email);

                res.send('hello',rows[i].email)

            }


        }
    }

    })

});



via dark night

No comments:

Post a Comment