choi

add board page function

const { WSAECONNRESET } = require('constants');
const e = require('express');
var express = require('express');
const { connect } = require('http2');
......@@ -14,18 +15,20 @@ router.get('/list/:page', function(req, res, next) {
else{
var page = req.params.page;
var sql = "select idx, name, title, date_format(modidate,'%Y-%m-%d %H:%i:%s') modidate, " +
"date_format(regdate,'%Y-%m-%d %H:%i:%s') regdate from board";
"date_format(regdate,'%Y-%m-%d %H:%i:%s') regdate,hit from board";
board.query(sql, function(err,rows) {
if (err) console.error("err : " + err);
var id = req.user.ID;
var nickname = req.user.nickname;
console.log(req.user.ID+'('+nickname+') 유저가 게시판을 보고있습니다.')
res.render('list.ejs', {'ID':id, 'nickname': nickname, title: '게시판 리스트', rows: rows})
res.render('list.ejs', {'ID':id, 'nickname': nickname, title: '게시판 리스트', rows: rows, page:page, length:rows.length-1,page_num:10,pass:true})
console.log(rows.length-1)
})
}
});
router.get('/list', function(req,res,next){
var id = req.user;
if(!id) res.sendFile(path.join(__dirname, "../../public/login.html"))
......
......@@ -45,9 +45,11 @@
<td>등록일</td>
</tr>
<%
for(var i=0; i<rows.length; i++)
{
var data = rows[i];
for(var i = (page * page_num) - page_num; i < (page * page_num); i++) {
if(i > length){
i++;
}else{
var data = rows[i]
%>
<tr>
<td><%=data.idx%></td>
......@@ -57,7 +59,20 @@
<td><%=data.modidate%></td>
<td><%=data.regdate%></td>
</tr>
<%}%>
<% }
}
%>
<tr>
<td colspan="6">
<%
for(var j = 0; j < rows.length / page_num; j++){
%>
[<a href="/board/page/<%= j + 1 %>"><%= j + 1 %></a>]
<%
}
%>
</td>
</tr>
</table>
</div>
<!-- Footer-->
......