SQL Auto Increment在同一张表中多次

编程入门 行业动态 更新时间:2024-10-19 14:49:49
本文介绍了SQL Auto Increment在同一张表中多次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我为我的一个朋友设计的网站上的内置管理面板有一个基本的HTML输入表单.他的想法是让他将用PHP脚本编写的数据发布到数据库中,然后将其放回到索引页面上.

I have a basic HTML input form for an inbuilt admin panel on a website that I'm designing for a friend of mine. The idea is for him to post data scripted with PHP to the database, which is then spat back out onto the index page.

问题:

每个条目显然在db中都有自己的列(id,name,ep_num等). id将自动递增到数据库中,名称被收集为$_POST['name'],但是对于ep_num,我想为每个名称分配自动递增.

Each entry obviously has its own column in the db (id, name, ep_num etc). The id is auto incremented into the database, the name is gathered as a $_POST['name'], however for ep_num, I would like to assign auto increments per name.

EG:

他发布了一次"Hello",它的ep_num为"1" 他输入了世界"一次,给出了ep_num为"1" 他再次输入"Hello",其ep_num为"2"

He posts "Hello" once, it is given the ep_num of "1" He inputs "World" once, it is given the ep_num of "1" He inputs "Hello" again, it is given the ep_num of "2"

我工作了很长的一天,并且相信mysql_insert_id()可能就是我想要的,我只是在努力地发挥自己的作用,并希望你们中的一个能帮助我.

I've had a long day at work, and believe that mysql_insert_id() may be what I'm looking for, I'm just struggling to put my brain to work and was hoping one of you guys to aid me.

预先感谢, 丰富

推荐答案

insert into t (name, ep_num) select 'b', count(*)+1 from t where name='b';

在sqlfiddle上进行演示

更多推荐

SQL Auto Increment在同一张表中多次

本文发布于:2023-11-22 06:41:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1616357.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:在同一   Auto   SQL   张表中   Increment

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!