带有 JQuery Droppable 的 MySQL 项目数据库
我的问题的简单版本: 当将 JQuery UI 可拖动图像放入我的目标可放置图像时,是否可以获取它的 ID,并使用该 ID 作为值,并在可拖动图像被放置时更新我的 MySQL 数据库表之一中的字段?
我的问题的技术版本: 我使用网站上的教程为我目前正在开发的游戏制作拖放库存功能。
无论如何,我无法提供到我的网站的直接链接,因为它需要登录,而且我还没有让我的系统在我的 IP 地址之外工作,但这就是我基本上想做的:
我的拖放效果很好,但我需要它来更新 MySQL 数据库,我知道我链接的教程中,它有第二部分可以做到这一点,但不是我需要的方式。
因此,我的用户的库存有自己的表,其中包含以下字段:
bid:这是存储为 32 位唯一随机数的用户 ID itemid:这是一个 8 位数的项目代码
用户和对象的所有信息都是内连接的,以将信息组合到 PHP 变量中,我将这些信息拆分到不同的表中,因为我有多个站点来调整每个表。到目前为止,这里一切正常。
我使用 mysql_fetch_array() 将项目加载到库存框中以使它们可拖动。
我的物品格式如下:
img src='$cheesepic' id='$itemid' class='object cheese'
$cheesepic == "http://motb.isgreat.org/objects/" . $itemid . ".png";
并且 $item
id 直接从库存表中窃取。 CSS 类对象将图像缩放到我想要的大小,我比缩略图更喜欢它,因为它的缓存效果更好,因为我在网站周围使用了许多不同大小的对象。奶酪类用于拖动,因此仅被奶酪可掉落物接受。
现在我的数据库中有另一个表用于存放已装备的对象。所以那里的字段是 bid 和 Cheese。我希望能够使用拖入可放置的图像的 ID 来更新我的数据库。如果他们将其从可放置项中拖出并再次放入可放置项库存中,则删除该行。
感谢您的帮助。
Simple Version of my question:
Is it possible to take a JQuery UI draggable image's ID, when it's dropped into my goal droppable, and use the ID as a value and update a field in one of my MySQL database tables when the draggable image is dropped?
Technical Version of my question:
I used a tutorial from a website to make a drag and drop inventory feature for a game I am currently working on.
Anyways, I cannot give a direct link to my site, as it requires a login, and I haven't gotten my system to work beyond my IP address, but here is what I am basically trying to do:
My drag and drop works great, but I need it to update a MySQL Database, I know for the tutorial I have linked, it has a second part that does it, but not the way I need.
So my user's inventory has it's own table with the following fields:
bid: this is the user id stored as a 32 digit unique random number
itemid: this is an 8 digit item code
All the information for the user and the objects are Inner Joined to combine the information into PHP Variables, I split these up over different tables because I have multiple sites that adjust each one. So far everything works here.
I use mysql_fetch_array()
to load the items into the inventory box to make them draggable.
My items are formatted as so:
img src='$cheesepic' id='$itemid' class='object cheese'
$cheesepic == "http://motb.isgreat.org/objects/" . $itemid . ".png";
and $item
id is stolen directly from the inventory table. The CSS classes
object scales the image to my desired size, I like it better than thumbnails since it caches better because I use so many different sizes of the objects around the site. The cheese class is for dragging so it is only accepted by the cheese droppable.
Now I have another table in my database for the equipped objects. So the fields there are bid and cheese. I would like to be able to update my database with the ID of the image that was dragged into the droppable. And delete that row if they drag it out of the droppable and into the inventory droppable again.
Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
jQuery 拖放Drop API 让您获取被拖动项目的数据,这是您可能尝试执行的操作的示例(数据名称和表行名称只是随机估计):
PHP/MySQL 方面有点难以帮助你会发现,大多数游戏脚本都是非常具体的,但你可以按照以下方式做一些事情:
The jQuery Drag & Drop API let's you get the data of the item being dragged, here's an example of what you might be trying to do (data names and table row names are just random estimates):
The PHP/MySQL side of it is a bit harder to help you out with, seeing as most game scripts are really specific but you could do something along the lines of: