Need help with PHP and MySQL

徘徊边缘 提交于 2019-12-05 08:52:10

You're getting the LIMIT clauses wrong. it's OFFSET,QUANTITY. Your sample queries are fetching 5 records at a time, so the QUANTITY would be 5 at all times, and you'd increment the offset by 5 for each "page" of results.

Top 5 songs/albums: LIMIT 0,5
Top 6-10 songs/album: LIMIT 5,5
Top 11-15 songs/albums: LIMIT 10,5
etc...

Here's my quick stab at your question, but I'm making some huge assumptions.

I believe that you want all albums and singles listed in the order of release and you want to show 5 per "page". Assuming that, this query should work. Long term I would turn this into a view.

SELECT "Name", "Date Released"
FROM (
    SELECT "Album ID" as "Name", "Date Released" FROM Albums
    UNION ALL
    SELECT "Song Name" as "Name", "Date Released" FROM Songs WHERE "Album ID" IS NULL
) as AlbumsAndSingles
ORDER BY "Date Released" ASC
LIMIT X,5

Then, starting with 0, increment X in the query above by 5 on each page.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!