hi everybody
when i send friends data from database to blade template.
Sometimes it takes the information friends.length == 2 , and sometimes it does not receive data. freinds.length == 0
var friends = [];
var sql = 'SELECT users.id, users.name, users.avatar, users.online FROM friends, users WHERE EXISTS (SELECT * FROM users WHERE users.id = ? and friends.user_id = users.id ) and friends.friend_id = users.id';
sql = mysql.format(sql, req.session.userId);
mysqlConnection.query(sql, function (err, rows, fields) {
for(var i in rows) {
var row = rows[i];
friends[i] = {
avatar: row.avatar,
status: row.online ? 'online': 'offline',
userId: row.id
}
}
});
res.render('friends', {loggedIn: req.session.loggedIn, friends: friends});
i fixed, thnaks.
var friends = [];
var sql = 'SELECT users.id, users.name, users.avatar, users.online FROM friends, users WHERE EXISTS (SELECT * FROM users WHERE users.id = ? and friends.user_id = users.id ) and friends.friend_id = users.id';
sql = mysql.format(sql, req.session.userId);
mysqlConnection.query(sql, function (err, rows, fields) {
for(var i in rows) {
var row = rows[i];
friends[i] = {
avatar: row.avatar,
status: row.online ? 'online': 'offline',
userId: row.id
}
}
res.render('friends', {loggedIn: req.session.loggedIn, friends: friends});
});
hi everybody when i send friends data from database to blade template. Sometimes it takes the information
friends.length == 2
, and sometimes it does not receive data.freinds.length == 0
i fixed, thnaks.