[英]How do I store image sequence changes to a mysql database with php
I am trying to build a photo organization table and am looking for advice and/or examples of how to save the display sequence of photos to a database. 我正在尝试建立照片组织表格,并正在寻找建议和/或示例,以将照片的显示顺序保存到数据库中。 I'm using php and mysql 我正在使用php和mysql
Example: If I have 10 photos in an album and decide to change the sequence of images, so I move a photo from seq 2 to seq 7, then the sequence changes to the following. 示例:如果相册中有10张照片并决定更改图像顺序,那么我将照片从seq 2移到seq 7,则序列会更改为以下内容。
1, 2, 3, 4, 5, 6, 7, 8, 9, 10 Original Sequence 1、2、3、4、5、6、7、8、9、10原始序列
1, 7, 2, 3, 4, 5, 6, 8, 9, 10 New Sequence 1,7,2,3,4,5,6,8,9,10新序列
How do I tell the database that the sequence column for all the affected rows has changed? 如何告诉数据库所有受影响行的序列列已更改? ...in one operation. ...一次操作
Do I change multiple rows in the db at once? 我是否一次更改数据库中的多行? Can I limit to just the affected rows 我可以只限于受影响的行吗
the photos table currently has "rowID, sequence, URL...." 照片表当前具有“ rowID,序列,URL ...”
Consider having the same Sequence in the database and rather than changing sequences inside database overwriting it all the time, use a php random generator like so: 考虑在数据库中具有相同的Sequence,而不是始终更改数据库内部的序列以覆盖它,而使用php随机生成器,如下所示:
$db=new SQLite3("sqlite.db") or die ("Your Internet Connection Dropped!");
$select_table = $db->query("SELECT * FROM images");
while($image=$select_table->fetchArray(SQLITE3_ASSOC)){
echo "<img src='path/to/file/".$image[rand(1,11)].".png'>";
}
My Code is bad in security, but It should do the job, Hope it helps! 我的代码的安全性很差,但是应该可以完成工作,希望对您有所帮助!
UPDATE table SET display_order = CASE WHEN id=first_id THEN second_order ELSE first_order END WHERE id = first_id OR id = second_id LIMIT 2
在您具有first_id,first_order,second_id,second_order的位置,这将切换其显示顺序。
您也可以只将表写入具有next_image_id和previous_image_id的内容,这样插入图像所需要做的就是更改先前的图像next_image_id和下一幅图像的previous_id以及同一图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.