I am getting "deposited over undefined" result for current_game with this synthax when running node.js:
if(offer.items_to_receive == undefined) return;
mysqlConnection.query('SELECT `value` FROM `info` WHERE `name`=\'maxitems\'',
function(err, row, fields) {
if(offer.items_to_receive.length > row[0].value) {
offers.declineOffer({tradeOfferId: offer.tradeofferid});
offer.items_to_receive = [];
var unixtime = Math.round(new Date().getTime()/1000.0);
mysqlConnection.query('INSERT INTO `messages` (`userid`,`msg`,`from`, `win`, `system`, `time`) VALUES (\''+offer.steamid_other+'\',\'Sorry, but you deposited too many items\',\'System\', \'0\', \'1\', \''+unixtime+'\')', function(err, row, fields) {});
return;
} else {
mysqlConnection.query('SELECT `value` FROM `info` WHERE `name`=\'current_game\'',
function(err, row, fields) {
var current_game = (row[0].value);
mysqlConnection.query('SELECT COUNT(item) FROM `game' + current_game + '` AS maxitemperperson WHERE `userid`=\''+offer.steamid_other+'\'' , function(err, row) {
someVari = row[0].maxitemperperson;
console.log('Deposited over ' +someVari);
if((someVari + offer.items_to_receive.length) > 10) {
offers.declineOffer({tradeOfferId: offer.tradeofferid});
mysqlConnection.query('INSERT INTO `messages` (`userid`,`msg`,`from`, `win`, `system`, `time`) VALUES (\''+offer.steamid_other+'\',\'Sorry, but you deposited too many items\',\'System\', \'0\', \'1\', \''+unixtime+'\')', function(err, rowl, fields) {});
return;
}
})
})
}
});
Where is the error in the synthax? Basically, the first part till "else" is working, but afterwards I am trying to count the number of items from a certain table (which is generated dynamically through the current_game variable) that have the same userid and afterwards add another number of items and compare with 10 (which can also be written as row[0].value.
Any help would be appreciated.
You have the AS
alias in the wrong place in the SQL statement:
'SELECT COUNT(item) FROM `game' + current_game + '` AS maxitemperperson WHERE `userid`=\''+offer.steamid_other+'\''
This will alias the table name, so you could do COUNT(maxitemperperson.item)
to reference it (useful if you have more than one table in the query).
What you want is this:
'SELECT COUNT(item) AS maxitemperperson FROM `game' + current_game + '` WHERE `userid`=\''+offer.steamid_other+'\''