dongpan9760 2015-09-08 23:13
浏览 26
已采纳

SQL Auto在同一个表中多次递增

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.

The issue:

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:

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"

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.

Thanks in advance, Rich

  • 写回答

2条回答 默认 最新

  • dqsp60748 2015-09-09 00:08
    关注
    insert into t (name, ep_num) select 'b', count(*)+1 from t where name='b'; 
    

    Demo on sqlfiddle

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换