简单代码
SELECT SQL_CALC_FOUND_ROWS * from staff WHERE companyid='xxx' LIMIT 0,10; SELECT FOUND_ROWS() as total;
node JS 案例
let sqltxt=`SELECT SQL_CALC_FOUND_ROWS staffid,staffname,staffnum,departmen from staff WHERE companyid='xxx' LIMIT 0,10;` let sqltxt2=`SELECT FOUND_ROWS() as total` const P1=new Promise((resolve,reject)=>{ connection.query(sqltxt,function(err,data){ if(err){ reject(err) }else{ resolve(data) } }) }) const P2=new Promise((resolve,reject)=>{ connection.query(sqltxt2,function(err,data){ if(err){ reject(err) }else{ resolve(data) } }) }) Promise.all([P1,P2]).then(result=>{ res.send({ code: 200, msg: "查询成功!",data:result[0] ,total:result[1][0].total}).end(); },err=>{ console.log("err",err) })
新手 如果不对可以指出