最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
nodejs mysql如何实现分页
时间:2022-06-29 01:30:49 编辑:袖梨 来源:一聚教程网
这两天学习了nodejs mysql 实现分页,很重要,所以,今天添加一点小笔记。
代码如下
| 代码如下 | 复制代码 | 
| varexpress = require('express'); varrouter = express.Router(); varsettings = require('../settings.js'); varmysql = require('mysql2'); 
 router.get('/',function(req, res, next) { varcurrent_page = 1;//默认为1 varnum = 9;//一页条数 if(req.query.page) { current_page = parseInt(req.query.page); } 
 varlast_page = current_page - 1; if(current_page <= 1) { last_page = 1; } varnext_page = current_page + 1; varstr ='SELECT left(paragraph,50) as paragraph,date,id FROM notice limit '+ num +' offset '+ num * (current_page - 1); varconn = mysql.createConnection(settings.db); 
 conn.connect(); conn.query(str,function(err, rows, fields) { if(err) { req.flash('error','数据查询有误'); } if(!err) { if(!rows[0]) { req.flash('error','已到最后一页,请返回'); } res.render('notice', { last_page: last_page, next_page: next_page, current_page: current_page, mes: rows, error: req.flash('error').toString() }); 
 } }); conn.end(); }); 
 module.exports = router; | |
相关文章
- 暗喻幻想布丽吉塔设施完工时间说明 10-31
- 三国志8重制版居民情感作用介绍说明 10-31
- 三国志8重制版游戏灾害效果介绍说明 10-31
- 三国志8重制版武将不同状态区别说明 10-31
- 三国志8重制版武将阶级提升方法分享 10-31
- 三国志8重制版武将不同阶级作用说明 10-31
 
             
                                 
                                 
                                 
                                 
                                            
                                         
                                            
                                         
                                            
                                         
                                            
                                         
                                            
                                         
                                            
                                         
                                            
                                         
                                            
                                         
                                            
                                        