简体   繁体   中英

PHP/MySQL: Get one row and the next five rows

I have one row that i can SELECT with the following command:

SELECT * FROM uploads WHERE upload_id = $upload_id

But I also want to get the 5 next rows. Using PHP, how can i do that? Order doesn't matter.

To get that record and the next 5 ascending upload_ids:

SELECT * 
FROM uploads 
WHERE upload_id >= $upload_id
ORDER BY upload_id ASC
LIMIT 6

You can try:

select * from uploads where upload_id >= $upload_id order by upload_id asc limit 6;

You should also really avoid using select * and instead specify only the fields you need, even if that is all of the fields. That way if the schema changes in the future you aren't returning redundant data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM