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

发布于 2024-09-14 03:54:48 字数 1725 浏览 5 评论 0原文

我正在使用 这个 jQuery 可编辑发票的绝佳示例作为创建动态的模板我的用户的发票。

它工作得很好,我成功地生成了项目,但我现在需要保存输入到各个文本字段中的值并将它们输入到 MySQL 数据库中。

我对使用 PHP 进行 MySQL 输入很有信心,但更棘手的是“发票项目”的数量是完全动态的,我不确定如何让 PHP 通过页面文本字段“检查”并找到新的,将它们分组,然后将它们添加到我的数据库中。

以下是我用来生成项目的代码示例:

<?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 } ?>  

我想我可能需要为每个发票项目文本字段生成唯一的 ID,即 item-1-descitem-1-cost 等,但这涉及编写我几乎一无所知的 JavaScript。另外,我仍然需要让 PHP 以某种方式循环遍历 ID,直到它到达末尾...

如果有人以前尝试过类似的操作,或者您可以看到我的问题的解决方案,我将非常感谢您的帮助。

谢谢,

蒂姆

I am using this fantastic example of a jQuery editable invoice as a template for creating dynamic invoices for my users.

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.

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.

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">
lt;?php echo $invoice_Row['hourly_cost']; ?>.00</textarea></td>
            <td><textarea class="qty"><?php echo $total_time_hours; ?></textarea></td>
            <td><span class="price">
lt;?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. Also I would still have to get PHP to loop through the ID's somehow until it reached the end...

If anyone has attempted something similar before or you can see a solution to my problem I would greatly appreciate your help.

Thanks,

Tim

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绝影如岚 2024-09-21 03:54:48

使用 php 表单数组语法 name="item-desc[]"

然后您可以在后端使用 foreach 迭代它们存储数据。您将 id 作为数组的键,因此更新数据库应该相当简单。

Use the php form array syntax name="item-desc[<?php echo $id?>]"

You can then iterate them on the backend with foreach to store the data. You have the id's as keys to the arrays so it should be fairly trivial to update the db.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文