如何在MySQL中动态更改Limit [英] How to change Limit dynamically in mySQL
本文介绍了如何在MySQL中动态更改Limit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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;
}
将其视为第二个查询,如果我运行的第一个查询的限制为5,则我将sendind 5作为$ lastOutputId作为参数,并且我希望将此查询作为5到5 + 5运行,并且在同一条件下方式,下一次查询将以10到15的范围运行.我该怎么办?
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可能有2个参数.在我们的情况下,我认为您可以像这样使用LIMIT:
LIMIT may have 2 parameters. In our case I think you can use LIMIT like this:
LIMIT $lastOutputId, 5
文档: http://php.about.com/od/mysqlcommands/g/Limit_sql.htm
这篇关于如何在MySQL中动态更改Limit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文