подскажите где ошибка
app.get('/orders/:page', (req, res) => {
var connection = getMySQLConnection();
var smartphone=[];
var allsmartphone={};
var smartphoneList=[];
var allprice=0;
var a;
var b;
var length;
var orderids
var raddr=req.connection.remoteAddress;
var start;
var end;
var allprice;
start=(req.params.page-1)*10;
end=req.params.page*10;
allprice=0;
connection.connect(function(err) {
if (err) throw err;
var sql3='SELECT `id` FROM `orders`';
var sql2='SELECT `orderid` FROM `orders` GROUP BY `orderid`';
var valuesii = [raddr];
connection.query(sql3, [], function (err, resulta) {
if (err){
console.log(err);
}else{
length=resulta.length;
if(start<0){start=0;}
if(end>(length-req.params.page*10)%10){end=length;}
}
});connection.query(sql2, [], function (err, result) {
if (err){
console.log(err);
}else{
orderids=result;
}
});
var sql ='SELECT `id`,`prod`,`name`,`photo`,`price`,`sale`,`remote_adr`,`quantity` FROM `orders` LIMIT ?,?';
connection.query(sql, [start,end], function (err, results) {
if (err){
console.log(err);
}else{
for(var j=0;j<1;j++) {
allprice = 0;
for (var i = 0; i < 1; i++) {
// Create the object to save the data.
b = results[i].price - results[i].price * results[i].sale / 100;
a = b * results[i].quantity;
allprice += a;
var smart = {
'id': results[i].id,
'prod': results[i].prod,
'name': results[i].name,
'photo': results[i].photo,
'sale': results[i].sale,
'price': results[i].price,
'tsale': b,
'vsego': a,
'quantity': results[i].quantity,
'allprice': allprice,
};
smartphone.push(smart);
}
allsmartphone[orderids[j]['orderid']][j] = smartphone;
}
var smartphoneList={
'len':length,
'jlen':end,
'ip':valuesii,
}
console.log(orderids[1]['orderid']+" :smart: "+allsmartphone[orderids[1]['orderid']][0]['id']);
res.render('orders', {"smartphoneList": smartphoneList,"allsmartphone": allsmartphone,'orderids':orderids});
}
});
});
});
<table>
<%for (var j=0;j<orderids.length;j++){%>
<%for(var i=0;i<smartphoneList['jlen'];i++){%>
<tr></tr>
<tr>
<td class="leftitem" style="padding:10px;border-left:1px solid silver;border-top:1px solid silver;border-bottom:1px solid silver;">
<img class="imgind" style="height:200px;width:200px" src="<%= allsmartphone[orderids[j]['orderid']][i]['photo'];%>" />
<p>
Производитель: <%= allsmartphone[orderids[j]['orderid']][i]['prod'];%><br>
Модель: <%= allsmartphone[orderids[j]['orderid']][i]['name'];%><br>
Цена: <%= allsmartphone[orderids[j]['orderid']][i]['price'];%><br>
<%if(allsmartphone[orderids[j]['orderid']][i]['sale']){%>Цена со скидкой:<%=allsmartphone[orderids[j]['orderid']][i]['tsale'];%> <br><%}%>
</p>
</td>
<td style="padding:10px;border-top:1px solid silver;border-bottom:1px solid silver;">
<input type="text" id="quan" onblur="quanaddbasket(this.value,{<%= allsmartphone[orderids[j]['orderid']][i]['id'];%>})" name="quan" value="<%=allsmartphone[orderids[j]['orderid']][i]['quantity'];%>" />
</td>
<td style="padding:10px;border-top:1px solid silver;border-bottom:1px solid silver;">Всего: <%= allsmartphone[orderids[j]['orderid']][i]['vsego'];%><td>
</td>
<td style="padding:10px;border-top:1px solid silver;border-right:1px solid silver;border-bottom:1px solid silver;"></td>
<tr>
<tr></tr>
<%}%>
<%}%>
</table>