Почему то логика не срабатывает и query равно ничему
app.get('/smart', function(req, res) {
var order;
var side;
var query;
var smartphopneList=[];
order='price';
side='ASC';
// Connect to MySQL database.
var connection = getMySQLConnection();
connection.connect();
// Do the query to get data.
if((order=='name') && (side =='ASC')){
query='SELECT `id`,`prod`,`name`,`description`,`photo`,`price`,`popularity`,`sale` FROM `smartphone` ORDER BY `name` ASC';
}else if((order=='name') && (side=='DESC')){
query='SELECT `id`,`prod`,`name`,`description`,`photo`,`price`,`popularity`,`sale` FROM `smartphone` ORDER BY `name` DESC';
}else if((order=='price') && (side=='ASC')){
query='SELECT `id`,`prod`,`name`,`description`,`photo`,`price`,`potypulari`,`sale` FROM `smartphone` ORDER BY `price` ASC';
}else if((order=='price') && (side=='DESC')){
query='SELECT `id`,`prod`,`name`,`description`,`photo`,`price`,`popularity,`sale`` FROM `smartphone` ORDER BY `price` DESC';
}else if((order=='popularity') && (side=='ASC')){
query='SELECT `id`,`prod`,`name`,`description`,`photo`,`price`,`popularity`,`sale` FROM `smartphone` ORDER BY `popularity` ASC';
}else if((order=='popularity') && (side=='DESC')){
query='SELECT `id`,`prod`,`name`,`description`,`photo`,`price`,`popularity`,`sale` FROM `smartphone` ORDER BY `popularity` DESC';
}else if((order=='sale') && (side=='DESC')){
query='SELECT `id`,`prod`,`name`,`description`,`photo`,`price`,`popularity`,`sale`,(`price` / 100 * `discount`) AS `tsale` FROM `smartphone` ORDER BY `newprice` ASC';
}else if((order=='sale') && (side=='DESC')){
query='SELECT `id`,`prod`,`name`,`description`,`photo`,`price`,`popularity`,`sale`,(`price` / 100 * `discount`) AS `tsale` FROM `smartphone` ORDER BY `newprice` DESC';
}
connection.query(query, function(err, rows, fields) {
if (err) {
res.status(500).json({"status_code": 500,"status_message": "internal server error"});
} 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,
'len':rows.length,
'tsale':rows.tsale,
'popularity':req.cookies.sidepopularity,
'pricee':req.cookies.sideprice,
'sale':req.cookies.sidesale,
'sett':req.cookies.sett,/**/
}
// Add object into array
smartphopneList.push(smartphopne);
}
// Render index.pug page using array
res.render('index', {"smartphopneList": smartphopneList});
}
});
// Close the MySQL connection
connection.end();
});
где ошибка