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 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行