简体   繁体   English

使用PHP将“ jQuery可编辑发票”的值提交到MySQL数据库

[英]Submitting values of “jQuery Editable Invoice” into a MySQL DB using PHP

I am using this fantastic example of a jQuery editable invoice as a template for creating dynamic invoices for my users. 我正在使用这个 jQuery可编辑发票的出色示例作为模板来为我的用户创建动态发票。

It's working quite well and I am successfully generating the items but I now need to save the values entered into the various text fields and enter them into the MySQL database. 它运行良好,并且我已经成功生成了项,但是现在我需要保存输入到各个文本字段中的值,并将它们输入到MySQL数据库中。

I am confident in doing the MySQL entering with PHP but what makes this trickier is that the amount of 'invoice items' is completely dynamic and I am unsure how I can get PHP to 'check' through the pages text fields and find new ones, group them and then add them to my DB. 我有信心在MySQL中使用PHP进行输入,但是使这一点更棘手的是“发票项”的数量是完全动态的,并且我不确定如何使PHP通过页面文本字段“检查”并找到新的,将它们分组,然后将它们添加到我的数据库中。

Here is an example of my code that I am using to generate the items: 这是我用来生成项目的代码示例:

<?php if($invoice_items->result_array()) { ?>
<?php foreach($invoice_items->result_array() as $invoice_Row): ?>
    <tr class="item-row">
            <td class="item-name">
            <div class="delete-wpr">
                <textarea><?php echo $invoice_Row['item_name']; ?> Facility Booking</textarea>
                <a class="delete" href="javascript:;" title="Remove row">X</a>
            </div>
        </td>
            <td class="description">
                <textarea><?php echo $invoice_Row['description']; ?></textarea>
            </td>
            <td><textarea class="cost">$<?php echo $invoice_Row['hourly_cost']; ?>.00</textarea></td>
            <td><textarea class="qty"><?php echo $total_time_hours; ?></textarea></td>
            <td><span class="price">$<?php $unit_total = $invoice_Row['hourly_cost']* $total_time_hours; echo $unit_total;?>.00</span></td>
    </tr>
<?php endforeach; ?>
<?php } ?>  

I am thinking that I need to perhaps generate unique ID's for each invoice items text field, ie item-1-desc , item-1-cost etc, but that involves writing javascript which I know almost nothing about. 我认为我可能需要为每个发票项目文本字段生成唯一的ID,即item-1-descitem-1-cost等,但这涉及编写我几乎一无所知的javascript。 Also I would still have to get PHP to loop through the ID's somehow until it reached the end... 而且我仍然必须让PHP以某种方式循环遍历ID,直到到达末尾为止。

If anyone has attempted something similar before or you can see a solution to my problem I would greatly appreciate your help. 如果有人以前曾尝试过类似的操作,或者您可以看到我的问题的解决方案,我们将非常感谢您的帮助。

Thanks, 谢谢,

Tim 蒂姆

Use the php form array syntax name="item-desc[<?php echo $id?>]" 使用php表单数组语法name="item-desc[<?php echo $id?>]"

You can then iterate them on the backend with foreach to store the data. 然后,您可以在后端使用foreach对其进行迭代以存储数据。 You have the id's as keys to the arrays so it should be fairly trivial to update the db. 您将id作为数组的键,因此更新数据库应该相当简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM