php - MySql/PHP - 如何同时将数据插入2个不同的表中(使用数组)

标签 php mysql arrays insert

我有一个创建请求的表单。通过单击“创建请求”按钮,所有信息都会添加到“Requests_Table”中。这工作得很好。每个请求都有多个项目(至少一个)...并且每个项目都由其自己的特征组成(这就是为什么我想将此信息存储在单独的表“SerialNumber_Table”上。

因此,我需要帮助将序列号信息(类型、型号、序列号)插入“SerialNumber_Table”。我相信我还需要使用 mysql_insert_id();将每个序列号与正确的 request_id 相关联。

` //序列号变量

    $machineType = mysql_prep($_POST['machineType']);
    $machineModel = mysql_prep($_POST['machineModel']);
    $serialNumber = mysql_prep($_POST['serialNumber']);

            <fieldset class="row2">
            <h1><?php echo $LANG['hardware_details']; ?></h1>
            <p style="margin: 10px 0 10px 0; ">
                <p style="margin: 10px 0 10px 0; font-size:12px; padding: 0;"><?php echo $LANG['delete_machines']; ?></p>
                <input type="button" value="<?php echo $LANG['add_machines']; ?>" onClick="addRow('dataTable')" style="width: 100px; padding: 2px 5px 2px 5px; background: #e1e1e1; color: #000; font-weight: bold; font-size: 12px; cursor: pointer;" /> 
                <input type="button" value="<?php echo $LANG['remove_machines']; ?>" onClick="deleteRow('dataTable')" style="width: 130px; margin-left: 10px; padding: 2px 5px 2px 5px; background: #e1e1e1; color: #000; font-weight: bold; font-size: 12px; cursor: pointer;" /> 
            </p>
           <table id="dataTable" class="form" border="1">
              <tbody>
                <tr>
                    <td><input type="checkbox" style=" width: 30px; "/></td>
                    <td>
                        <label style="margin-left: 10px;"><?php echo $LANG['machineType']; ?></label>
                        <input type="text" value="" id="machineType" name="machineType[]" style="width: 70px; margin: 5px 10px 10px 10px; ">
                     </td>
                     <td>
                        <label for="" style="margin-left: 10px;"><?php echo $LANG['machineModel']; ?></label>
                        <input type="text" value="" id="machineModel" name="machineModel[]" style="width: 70px; margin: 5px 10px 10px 10px;">
                     </td>
                     <td>
                        <label for="" style="margin-left: 10px;"><?php echo $LANG['serialNumbers']; ?></label>
                        <input type="text" value="" id="serialNumber" name="serialNumber[]" style="width: 120px; margin: 5px 10px 10px 10px;">
                     </td>
                </tr>
                </tbody>
            </table>
            <div class="clear"></div>
        </fieldset>

            <!-- End Dynamic Forms for Serial Numbers -->

` 我怎样才能完成这样的任务呢? 如果有任何帮助,我已将此页面的完整代码发布在 http://aerco.com.br/stackoverflow/source.txt

有人可以在这里指出我正确的方向吗? 预先感谢您的任何想法

最佳答案

我无法了解您的确切需求,但据我了解,您可以使用代码插入一个表,使用 MySQL 触发器插入另一个表。

在这里解释:http://dev.mysql.com/doc/refman/5.0/en/triggers.html

关于php - MySql/PHP - 如何同时将数据插入2个不同的表中(使用数组),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19485479/

相关文章:

mysql - INSERT INTO SELECT 子查询返回多于 1 行

php - PHP/MySQL并行插入的正确处理

mysql - 通过具有 : SQLite vs MySQL 进行分组

java - 无法使用 Apache Commons Lang 将双数组转换为字符串

php - 该插件在激活期间生成了 X 个字符的意外输出(WordPress)

php - 社交网站时间线的数据库查询

arrays - Swift - 如果包含字符串并附加到另一个数组,则在数组中搜索

php - Codeigniter 事件记录 - 使用数组中的数据更新查询

php - 日期时间区错误 : Unknown or bad timezone

php - 更改 php 数组看起来像 jquery 数组(谷歌图表)