作者:小文662502914775 | 来源:互联网 | 2023-05-17 18:08
Thisonemightbeabitcomplicated.Isearchedforsimilarquestionsandfoundnothingthatseemed
This one might be a bit complicated. I searched for similar questions and found nothing that seemed relevant.
这个可能有点复杂。我搜索了类似的问题,发现没什么看似相关的。
Let me start by establishing my database structure.
首先让我建立我的数据库结构。
I have several tables, but the relevant ones are as follows:
我有几张表,但相关的表如下:
Right now I have the decklist stored as a string of cardid
delimited by a comma. I realize this is inefficient and when I get around to improving my code I will make a new table tcg_card_in_deck
that has relationid
, cardid
, deckid
. For now my code assumes a decklist
string.
现在我将decklist存储为由逗号分隔的cardid字符串。我意识到这是低效的,当我开始改进我的代码时,我会创建一个新的表tcg_card_in_deck,它具有relationid,cardid,deckid。现在我的代码假设一个decklist字符串。
I'm building a function to allow purchases of a deck. In order to give them the actual cards, I have the following query (generated with the PHP it will actually be about 50 entries):
我正在建立一个允许购买套牌的功能。为了给他们实际的卡片,我有以下查询(用PHP生成它实际上将是大约50个条目):
$db->query_write("INSERT INTO
`tcg_card`
(masterid, userid, foil)
VALUES
('159', '15', '0'),
('209', '15', '0'),
('209', '15', '0'),
('318', '15', '0')");
This part is easy. My issue now is making sure the cards that have just been added can have their ids grabbed and put together in an array (to enter in as a string currently, and as entries into the separate table once the code is updated). If it was one entry I could use LAST_INSERT_ID()
. If I did 50 separate insert queries I could grab the id on each iteration and add them into the array. But because it's all done with one query, I don't know how to effectively find the correct cards to put in the decklist. I suppose I could add a dateline field to the cards table to specify date acquired, but that seems sloppy and it may produce flawed results if a user gets cards from a trade or a booster pack in a similar timeframe.
这部分很容易。我现在的问题是确保刚刚添加的卡可以抓取它们并将它们组合在一个数组中(以当前字符串形式输入,并在代码更新后作为条目输入到单独的表中)。如果是一个条目,我可以使用LAST_INSERT_ID()。如果我做了50个单独的插入查询,我可以在每次迭代时获取id并将它们添加到数组中。但由于这一切都是通过一个查询完成的,我不知道如何有效地找到正确的卡片放入套牌清单。我想我可以在卡片表中添加一个日期行字段来指定获得的日期,但这看起来很草率,如果用户在相似的时间范围内从交易或助推器包中获得卡片,则可能会产生有缺陷的结果。
Any advice would be appreciated!
任何意见,将不胜感激!
2 个解决方案