duande1985 2019-02-13 10:06
浏览 192
已采纳

我想在一个列中使用单个主键在数据库中插入多个数据

I want to insert multiple data into table in single column with same primary key when form is submitting using php sql.

Here is the filled form -

form with data

I want to insert into table using php & sql (ajax if need) like this below link-

[table with data i hope

  • 写回答

3条回答 默认 最新

  • dsyo9700 2019-02-13 10:48
    关注

    I had same isssue while making API for PHP.

    Try this , declare your Item name , quanity and date as TEXT and insert nested JSON in those fields.

    i.e.

    //while adding to DB json will look like
    
    "[{ABC},{PQR},{XYZ}]","[{23},{56},{14}]","[{23/05/1900 12:00 GMT},{23/05/1908 12:00 GMT},{23/05/1980 12:00 GMT}]"

    So,

    "[{ABC},{PQR},{XYZ}]" go to item_name column,

    "[{23},{56},{14}]" goes to quantity column,

    "[{23/05/1900 12:00 GMT},{23/05/1908 12:00 GMT},{23/05/1980 12:00 GMT}]" goes to date column

    as simple string or text. Here's below is my HTML Code for Table (Ignore style ☺)

    <table>
        <thead>
        <tr>
        <td>ITEM_NAME</td>
        <td>QUANTITY</td>
        <td>DATE</td>
        </tr>
        </thead>
        <tbody>
        <tr>
        <td>ABC</td>
        <td>23</td>
        <td>23/05/1900 12:00 GMT</td>
        </tr>
            <tr>
        <td>PQR</td>
        <td>56</td>
        <td>23/05/1908 12:00 GMT</td>
        </tr>
            <tr>
        <td>XYZ</td>
        <td>14</td>
        <td>23/05/1980 12:00 GMT</td>
        </tr>
        </tbody>
    

    So while adding to Database you need first push data to object then Stringyfy it and then send to database. And while fetching from database and displaying again to UI , you need to Parse those strings back to Objects then you can apply looping like it is an Nested object.

    Happy Codeing ☻

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

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘