开发者

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.

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 开发者_StackOverflowif($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. 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜