Skip to content

Commit

Permalink
添加用户所有文章统计数
Browse files Browse the repository at this point in the history
  • Loading branch information
sumory committed Mar 29, 2012
1 parent ae668c9 commit ff14d55
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion controller/sign.js
Expand Up @@ -153,7 +153,7 @@ exports.signin = function(req, res, next) {
}

gen_session(user, res);// store session cookie
console.log('gen_session->redirect');
//console.log('gen_session->redirect');
res.redirect('home');
});

Expand Down
18 changes: 15 additions & 3 deletions controller/site.js
Expand Up @@ -4,10 +4,22 @@ var mysql = require('../lib/mysql.js');
exports.index = function(req, res, next) {

mysql.query('select * from user', function(err,users){//得到所有的用户
res.render('index', {
users : users
mysql.query('select count(id) as count, author_id from archive group by author_id', function(err,result){
for(var i = 0; i < users.length; i++){
for(var j=0;j<result.length;j++){
if(users[i].id==result[j].author_id){
users[i].archive_count = result[j].count;
break;
}
}
}

res.render('index', {
users : users
});
return;
});
return;

});

};
8 changes: 3 additions & 5 deletions view/index.html
Expand Up @@ -41,14 +41,12 @@
<% } %>
<span class='user_name'><a class='dark' href='/user/<%= user.id %>'><%= user.loginname %></a></span>
<div class='sep5'></div>
<span class='col_fade'></span>
<span class='sp5'></span>
<span class='col_fade'></span>
<span class='col_fade'>文章数: <%=user.archive_count?user.archive_count:0%></span>

</div>
<div class='sep10'></div>
</div>
<%}%>



</div>
</div>

0 comments on commit ff14d55

Please sign in to comment.