dqdjfb2325 2014-01-17 21:45
浏览 17

将自动递增的值添加到另一个表

I have 2 tables:

1)'table'
    'id' - int autoincremented
    'name' - string

2) 'table2'
     'id' - int
     'info' - string

Lets, say the last row in table has id=20

After I insert 5 empty rows to table, last row has id=25

INSERT INTO `table` (`name`)
VALUES ((""),(""),(""),(""),(""))

1) First thing I need is to add 5 rows with same id-s and empty info-s to table2, right after they were added to table. Something like that:

INSERT INTO `table2` (`id`,`info`)
VALUES ((21,""),(22,""),(23,""),(24,""),(25,""))

Can I do it using one statement?

2) Second thing I need is to extract these values to a PHP variable, like array or string (21,22,23,24,25), so that it could be used for further actions. Is it possible at all?

  • 写回答

2条回答 默认 最新

  • dongnuo3749 2014-01-17 21:50
    关注

    1- you cant insert in two tables with one statment. you need two statments.

    2- and if you using Mysqli or pdo you already have the option to bind parameters to variables.

    edit>

        $stmt->store_result();
        $stmt->bind_result($id); ---------> here you will get $id as variable of those ids
    
    评论

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?