bminer / node-blade

Blade - HTML Template Compiler, inspired by Jade & Haml
Other
320 stars 28 forks source link

Problem in sending data #199

Closed m-jch closed 10 years ago

m-jch commented 10 years ago

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});
});