не могу запустить 2 запроса к бд выдает оштибку
пишет Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
app.get('/smart', function(req, res) {
var order;
var side;
var prmin;
var prmax;
order=req.cookies.sett;
if(order=='price'){
side=req.cookies.sideprice;
}else if(order='popularity'){
side=req.cookies.sidepopularity;
}else if(order='tsale'){
side=tsale;
}
if(!order){order='name';}
if(!side){side='ASC';}
var query;
var smartphopneList=[];
// Connect to MySQL database.
var connection = getMySQLConnection();
var connection1 = getMySQLConnection();
connection1.connect();
// Do the query to get data.
quer='SELECT `id`,`prod`,`name`,`description`,`photo`,`price`,`popularity`,`sale`,(`price` -`price` / 100 * `sale`) AS `tsale` FROM `smartphone` ORDER BY `ptice` ASC';
connection1.query(quer, function(err, rowes, fields) {
if (err) {
res.status(500).json({"status_code": 500,"status_message": "internal server error"});
console.log(err);
} else {
// Loop check on each row
prmin=rowes[0];
prmax=rowes[(rowes.length-1)];
}
// Render index.pug page using array
});
connection1.end();
connection.connect();
query='SELECT `id`,`prod`,`name`,`description`,`photo`,`price`,`popularity`,`sale`,(`price` -`price` / 100 * `sale`) AS `tsale` FROM `smartphone` ORDER BY '+order +" "+side;
connection.query(query, function(err, rows, fields) {
if (err) {
res.status(500).json({"status_code": 500,"status_message": "internal server error"});
console.log(err);
} else {
// Loop check on each row
for (var i = 0; i < rows.length; i++) {
// Create an object to save current row's data
var smartphopne = {
'id':rows[i].id,
'prod':rows[i].prod,
'name':rows[i].name,
'photo':rows[i].photo,
'description':rows[i].description,
'price':rows[i].price,
'sale':rows[i].sale,
'len':rows.length,
'tsale':rows[i].tsale,
'prmin':prmin,
'prmiax':prmax,
}
// Add object into array
smartphopneList.push(smartphopne);
}
// Render index.pug page using array
res.render('index', {"smartphopneList": smartphopneList});
}
});
// Close the MySQL connection
connection.end();
});