mysql limit换成_如何在MySQL中动态更改Limit

bd96500e110b49cbb3cd949968f18be7.png

public function getAllCelebDataFinal ($database,$celebrityId,$lastOutputId)

{

$getalldata = $database->executeObjectList("

SELECT *

FROM (

(SELECT v.vidId, NULL as newsId, NULL as photoId, NULL as imageFile,

v.title as vidTitle, NULL as newsTitle, v.videoLink AS vidLink,

NULL as newsVidLink, NULL as newDetail , v.addDate

FROM videos v

WHERE v.celebrityId='".$celebrityId."' AND v.isPublished=1)

UNION ALL

(SELECT NULL as vidId, n.newsId,NULL as photoId,NULL as imageFile,

NULL as vidTitle, n.title as newsTitle, NULL AS vidLink,

n.videoLink as newsVidLink, n.details as newDetail,

n.addDate

FROM news n

WHERE n.celebrityId='".$celebrityId."' AND n.isPublished=1)

UNION ALL

(SELECT NULL as vidId,NULL as newsId,p.photoId,p.imageFile,

NULL as vidTitle, NULL as newsTitle, NULL AS vidLink,

NULL as newsVidLink, NULL as newDetail , p.addDate

FROM photos p

WHERE p.celebrityId='".$celebrityId."' AND p.isPublished=1)

) results

ORDER BY addDate DESC

LIMIT 5");

return $getalldata;

}

Consider it as a second query, if i am running first query with the limit 5, i am sendind 5 as $lastOutputId as a parameter, and i want to run this query as 5 to 5+5, and in the same way, next query would run with limit 10 to 15. How can i do that?

解决方案

LIMIT may have 2 parameters. In our case I think you can use LIMIT like this:

LIMIT $lastOutputId, 5

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值