Показать сообщение отдельно
  #5 (permalink)  
Старый 15.10.2020, 11:35
Аспирант
Отправить личное сообщение для riaron Посмотреть профиль Найти все сообщения от riaron
 
Регистрация: 16.08.2020
Сообщений: 53

отредактировал сделал так
]).then ( () => {
	for(var j=0;j<orderids.length;j++) {
		allprice = 0;
			var sql1 ='SELECT `id`,`prod`,`name`,`photo`,`price`,`sale`,`remote_adr`,`quantity` FROM `orders` where `orderid`=? LIMIT ?,?';
		return pquery (connection, sql1, [orderids[j],start,end]).then ( results => {
				for (var i = 0; i < end; i++) {
					// Create the object to save the data.
					b = results[i].price - results[i].price * results[i].sale / 100;//166 строка
					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);
				}
			}
		);
			var smartphoneList={
				'len':length,
				'jlen':end,
			}
		allsmartphone[j] = smartphone;
		console.log(orderids);
			res.render('orders', {"smartphoneList": smartphoneList,"allsmartphone": allsmartphone,'orderids':orderids});
		}
	}).catch (err => {

выдает ошибку
TypeError: Cannot read property 'price' of undefined
at C:\xampp\htdocs\mysite.local\app.js:166:21
at processTicksAndRejections (internal/process/task_queues.js:97:5)

надо ли с функцией ниже что то делать?
function getMySQLConnection() {
return mysql.createConnection({
host : 'localhost',
user : 'root',
password : '',
database : 'elektronika'
});
}

Последний раз редактировалось riaron, 15.10.2020 в 11:38.
Ответить с цитированием