单击创建下一张图像:上一张和下一张
我有一个场景,如果我有一个缩略图网格,并且用户单击一个图像,他们可以单击下一个(以查看网格中的下一个图像)或上一个(反之亦然)。
我会在 mysql 中有一个单独的表来存储这些图像源的列表,还是会使用类似数组之类的东西,或者还有其他更好的选择吗?我认为这是错误的,如果有数百万张图像,它会减慢服务器速度吗?
您也愿意举个例子吗?
谢谢你!
I have a scenario where if I have a grid of thumbnail images and a user clicks an image, they can click on next (to see next image in line from the grid) or previous (vice versa).
Would I have a separate table in mysql for a list of those image source, or would you use something like an array, or are there any other better options? I'm thinking this in the long wrong, if there's millions of images, it will slow down the server?
Would you be willing to show an example too?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定为什么会出现问题......如果您显示网格,则意味着您已经可以访问上一张/下一张图像,对吧?根据您拥有的用户数量,您可以简单地将显示网格中的图像 ID 列表放入会话中,然后您甚至不需要访问数据库(除了拉取图像本身)。当用户滚动浏览图像时(使用上一张/下一张),如果用户开始接近结尾,只需将其添加到列表中即可。
I'm not sure why there is an issue ... if you're showing a grid, that means you already have access to the previous/next image, right? Depending on how many users you have, you could simply put a list of image ids from the displayed grid into session, then you wouldn't even need to hit the database (except to pull the image itself). As the user is scrolling through the images (using prev/next), just add to the list if the user starts getting close to the end.
是的,您需要桌子。
因为您不应该将所有文件存储在一个目录中 - 因为目录有文件数量的限制。因此,您不能只从文件夹中读取“下一个”文件,因为该文件可能位于另一个文件夹中。
欲了解更多信息,请查看此处:
PHP 安全性和独特的命名约定
Yes, you need the table.
Because you shouldn't store all files in one directory - because directories have limits of count of files. So you can't just read "next" file from folder, because that file can be in another folder.
For additional info, look here:
PHP security and unique naming conventions
我认为你不需要为此拥有一个多维数组。您的图像仍应具有从 1 到 n 的连续 ID,以便轻松实现 next() 和 prev() 函数。
例如,我从 MySQL 查询中得到了这个结果。
然后,您可以在视图中处理网格生成。
然后你的 javascript 在图像之间切换应该更容易,因为你只需要增加和减少 ID,而不是在你有时计算它
I don't think you need to have a multi-dimensional array for this. Your images should still have a sequential ID from 1 to n so it will be easy to implement your next() and prev() function.
For example I have this result from my MySQL query.
Then you handle the grid generation in your view.
Then your javascript to toggle between images should be much easier as you only need to increment and decrement the ID, instead of computing for it when you have