gpt4 book ai didi

MYSQL 库存插槽(将项目添加到下一个免费插槽)

转载 作者:行者123 更新时间:2023-11-29 03:08:33 25 4
gpt4 key购买 nike

  $slt = mysql_query("select Slot, ItemId, UserId, max(Slot) Slot
from useritems
group by UserId");

while ($sloot = mysql_fetch_assoc($slt))
{
Echo "<br>Items with biggest slots are: " . $sloot['ItemId'] . " from user " . $sloot['UserId']. "- in slot-". $sloot['Slot'];
}

这是表格

Idi Quantity    ItemId  UserId  Slot    ExpirationDate

输出最小的槽...为什么?

1.我想向我展示每个用户的最大库存槽位,所以当我向他的库存添加一个新项目时,我可以在下一个槽位添加。例如用户 Paul 有 5 个项目占用了槽位 1,2, 3、4、5 和下一个项目将在插槽 6 上。

2.当用户将他的元素移动到插槽 1、2、4、5、6 时,下一个添加的元素将在插槽 3 上

我做了很多搜索,但我自己也找不到:) PS:我制作它的游戏只是为了好玩..但也许有一天会成为一款很棒的游戏: )(梦想,梦想:)))

编辑:

SQLFIDDLE 非常好,谢谢:) 这正是我学习一些 SQL 所需要的
表 useritems

useritems Table IMAGE
items Table

我的 Echo 告诉我:

Id = 1 and it should be 3; user=4(good); slot=4(good)
Id = 1 and it should be 2; user=5(good); slot=2(good)

最佳答案

也许是这样的:

select userid, itemid, max(slot) from useritems where itemid is not null and quantity>0
group by userid, itemid

如果您与一些数据共享您的表脚本,会更容易帮助您。

您可以使用:http://sqlfiddle.com/

编辑:

这个呢? itemid=0 表示插槽空闲?所以 min(slot) 将是用户的第一个空闲插槽。

select userid, min(slot) from useritems where itemid=0 group by userid

关于MYSQL 库存插槽(将项目添加到下一个免费插槽),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11723479/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com