rn3w rn3w - 1 year ago 75
MySQL Question

I have a function mysql in nodejs and can't parse the result

My function is:

objBD.query('SELECT MAX(ID_U) FROM usuario', function(err, rows, fields) {

The result is


I need the max number, example: 43

Answer Source

The rows variable returned by mysql's callback is an array, even if the result is only one row (as in the case of using max). To access the result you should access the first row of the array.

For example: console.log(rows[0].MAX)

This would access the first row of the array, and the MAX property within the object stored in that row, since each row is an object in mysql's results.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download