mysql id字段刚刚提交
好吧,我发现自己经常这样做。我会将 id 附加到我的表中,并将这些表“链接”在一起。举一个简单的例子,团队花名册可能有类别。每个类别都有一个 id。当我将玩家添加到名单中时,我还会为他们分配一个类别 ID,以表明他们属于该类别。
我的问题是,对于这个例子,假设我同时创建一个类别和一个玩家。我提交了类别,但现在我必须获取类别 ID 才能将其分配给玩家表行。关于如何有效地做到这一点有什么建议吗?目前我会再次查询数据库,搜索与类别相关的具体数据,这似乎不太有效。
另请注意,我使用的 id 是由 mysql 生成的。
任何建议都会有帮助!
Ok, I find myself doing this often. I'll attach ids to my tables and I'll "link" the tables together. Just a simple example, a team roster might have categories. Each category has an id. When I add players into the roster, I'll assign them a category id as well to signify that they are part of that category.
My question is, for this example, say I'm creating a category and a player at the same. I submit the category but now I have to get the category id to assign it to the player table row. Any suggestions on how to do this efficiently? Currently I would query the database again, and search for specific data related to the category, which doesn't seem very effective.
Note also, the id's Im using are generated by mysql.
Any suggestions would be helpful!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 mysql_insert_id()
Check out mysql_insert_id()