向MySQL数据库添加未知数量的值

向MySQL数据库添加未知数量的值

本文介绍了向MySQL数据库添加未知数量的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的情况是我正在创建一个wordpress插件,它会在激活时在目录中创建一个表.

My situation is that I am creating a wordpress plugin, it creates a table in the directory on activation.

此表保存输入到插件中的信息,当输入信息时,用户可以选择上传图像.他们不知道他们选择上传的号码.

This table holds information entered into the plugin, when information is being entered the user has the option to upload images. The number they will choose to upload I do not know.

我遇到的问题是弄清楚如何将这些URL添加到数据库中,确保可以将它们放入数据库中,但是我又不知道需要添加多少URL.

The issue I am having is figuring out how to add these URLS into the database, sure I can just put them in there but again I do not know how many URLS need to be added.

由于我无法对wordpress使用规范化,因此如何将URLS存储在数据库中.假设他们上传了5张图片,但我没有5个单独的列(URL 1,URL 2 ...)

As I cannot use normalization with wordpress, how would I store the URLS in the DB. Say they upload 5 images but I do not have 5 separate columns (URL 1, URL 2...)

我还应该注意,这些图像将使用for循环来获取,因此无论上载的数量是多少,每张图像都会被发送出去.

I should also note that these images will be fetched using a for loop, so each image will be sent off regardless of the number they are uploading.

任何帮助将不胜感激干杯.

Any help would be appreciatedCheers.

推荐答案

此外,您还可以使用以下方法制作其他表格:

Also, You can make additional table with:

id,information_id,文件名或ordr

首先,插入infromation_table中,获取最后插入的ID

Firstly, insert into infromation_table, get last inserted ID

然后,按顺序将所有文件名插入filenames_table

Then, insert into filenames_table all your filenames in order

最后,您可以选择数据:

Finally, you can select data:

SELECT i.id, i.title, GROUP_CONCAT(a.filename ORDER BY a.ordr ASC SEPARATOR ',') AS filenames
FROM information_table AS i
JOIN filenames_table AS a ON (a.information_id = i.id)

这篇关于向MySQL数据库添加未知数量的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 18:47