开发者

Random row, but with next and previous button

I have a MySQL database with pictures within it. When a user comes to my page I want to show him random picture and from then he can go to the next or previous picture (not random)

Database开发者_如何学运维 example

id | picture 
11 | foto1.gif
12 | foto2.gif
16 | foto3.gif
23 | foto4.gif
66 | foto5.gif

How can I make something like that with PHP and SQL? Thank you!


Use ORDER BY rand() in your query to get the random item.

To retrieve the next/previous item (by id), use this:

WHERE id < current_id ORDER BY id DESC LIMIT 1   (for prev)
WHERE id > current_id ORDER BY id ASC LIMIT 1   (for next)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜