简体   繁体   English

如何使用php将图像序列更改存储到mysql数据库

[英]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.

相关问题 如何在 MySql 数据库中将复选框值存储为是 - PHP - How do I store a checkbox value as yes in MySql Database - PHP 如何将 MySQL 数据库中的字段作为字符串存储在 PHP 中? - How do i store a field from a MySQL database as a string in PHP? 如何在数据库php / mysql中存储图像链接 - How to store image link in database php/mysql 如何将图像文件夹路径存储到MYSQL数据库中,并通过PHP和XAMPP在网页中显示图像? - How I will store image folder path into the MYSQL Database and display the image in a webpage via PHP and XAMPP? 我想通过php将图像存储在mysql数据库上作为blob类型 - I want to store image on mysql database as blob type by php 如何在iOS中使用Php MySql在数据库上存储图像 - How to store image on database using Php MySql in iOS 如何将 PHP imagecopymerge function 创建的图像存储在 mysql 数据库中 - How to store image created by PHP imagecopymerge function in mysql database 如何将图像存储到 MySQL 数据库中? - How to store image into MySQL database? 如何使用MySQL和PHP在数据库中的用户之间存储相关值? - How do I store correlation values between users in a database using MySQL and PHP? 如何获取数据库中字段名(名称)中的所有数据并将其存储在变量数组中? 在 PHP 和 MYSQL - HOw do i get all the data in a fieldname (Name) in database and store it in a variable array? in PHP and MYSQL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM