【问题标题】:how to add multiple arrays in form in mysql database php?如何在 mysql 数据库 php 中以表单形式添加多个数组?
【发布时间】:2017-11-30 11:37:07
【问题描述】:

我有一个获取产品数据库条目的表单。我在一个表单中添加了多行产品,我需要数据库插入方面的帮助。 我希望将数据添加到单行中,并且我有多个数组。

<form id='students' method='post' name='students' action='add-      
    <div class="table-responsive">
        <table class="table">
            <tr>
                <th><input class='check_all' type='checkbox' onclick="select_all()"/></th>
                <th>S. No</th>
                <th>BarCode</th>
                <th>HSN</th>
                <th>Product Name</th>
                <th>MRP</th>
                 <th>CGST</th>
                 <th>SGST</th>
            </tr>
            <tr>
                <td><input type='checkbox' class='case'/></td>
                <td><span name='snum[]' id='snum'>1.</span></td>
                <td><input class="form-control" type='text' id='countryname_1' name='countryname[]'/></td>
                <td><input class="form-control" type='text' id='country_no_1' name='country_no[]'/></td>
                <td><input class="form-control" type='text' id='phone_code_1' name='phone_code[]'/></td>
                <td><input class="form-control" type='text' id='country_code_1' name='country_code[]'/> </td>
                <td><input class="form-control" type='text' id='cgst_1' name='cgst1[]'/> </td>
                    <td><input class="form-control" type='text' id='sgst_1' name='sgst1[]'/> </td>
            </tr>
        </table>
        <input type="submit" value="submit">
        <button type="button" class='btn btn-danger delete'>- Delete</button>
        <button type="button" class='btn btn-success addmore'>+ Add More</button>
    </div>
</form>

【问题讨论】:

  • 请努力
  • 你的表结构和想要的输出是什么?你想要每个产品索引一行吗?全部用逗号隔开?等等。到目前为止,您尝试过什么?
  • 你的表格错了---&lt;form id='students' method='post' name='students' action='add- 在这里关闭
  • @kchason- 是的,我需要每个产品索引的行,我尝试了 pair() 和基本方法来存储数组,但我仅限于添加同名数组,但这里我有 5 个不同的名称数组这给我带来了麻烦。
  • @B001 - 谢谢,但我放置表格只是为了对数组有一个公平的想法

标签: php mysql arrays


【解决方案1】:

如果我正确理解了您的问题,您正在尝试将数组存储在数据库中。这本身是不可能的,但是您可以在获取数据时使用 serialize() 函数和 unserialize()。

PHP manual

【讨论】:

  • 谢谢michal-请您提供详细信息,听起来可以解决问题
猜你喜欢
  • 1970-01-01
  • 2017-03-28
  • 1970-01-01
  • 1970-01-01
  • 2023-03-24
  • 2019-09-30
  • 1970-01-01
  • 2018-01-26
  • 2016-04-07
相关资源
最近更新 更多