如何将多个数据到一个表 [英] How to insert multiple data into a table

查看:98
本文介绍了如何将多个数据到一个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表,每一行的项目各有一个addtocart按钮,当我点击addtocart按钮,模态表演和它有,我想订购,当我点击确定按钮另一个模式将显示数量确定按钮它有一个像第一个表的表的形式和它表明我订购的物品,当我点击确定按钮,我想在数据库上要插入的行。

I have a table and every row items have an addtocart button each and when i click the addtocart button, a modal shows and it has ok button for the qty that i want to order, when i click ok button another modal will show and it has the table form like the first table and it shows the items that i ordered, and when I click the ok button, I want that rows to be inserted on the database.

$( $table ).delegate(".Addtocart", "click", function() {
                var itemNo = $(this).closest('tr').find('td.itemNo').html();
                var selected_item = $(this).closest('tr').find('td.itemdescr').html();
                var remaining_qty = $(this).closest('tr').find('td.currqty').html();
                var unitPrice = $(this).closest('tr').find('td.unit_price').html();
                var amount = $(this).closest('tr').find('td.Amount').html();
                $("#action").val('add');
                $('#itemNo').val(itemNo);
                $('#selected_item').val($.trim(selected_item));
                $('#remaining_qty').val(remaining_qty);
                $('#unitPrice').val(unitPrice);
                $('#amount').val(amount);
                $('#myModal').modal('show');
            }); 

继承人为第二模态第二OK按钮

heres the 2nd ok button for the 2nd modal

$('#OKBtn2').click(function(){
            $('#myModal2').modal('hide');
            var itemid = $('#main-form2 .active').attr('id'),
                qty = $('#main-form2 #'+itemid+' td:eq(2)').text(),
                amount = $('#main-form2 #'+itemid+' td:eq(4)').text();
                bootbox.confirm("Are you sure?","No","Yes",function(r){
                    if(r) {
                        var itemno = $('#itemNo').val();
//                        var currqty = $('#orderqty').val();
                        var unit_price = $('#unitPrice').val();
//                        var Amount = $('#amount').val();
                        $.ajax({  
                            url : url,
                            type : "POST",
                            async : false,
                            data : {
                                    Modify: 1,
                                    Delete:1,
                                    Add: 1,
                                    itemNo: itemno,
                                    orderqty: qty,
                                    unit_price: unit_price,
                                    amount: amount,
                                    todo:"Add"
                                       },
                        success:function(result){
                        bootbox.alert('Ordered',function(){
                        });
                        updateTable();
                        }
                    });

                    } else {

                    }
                });
            });

我怎么能转换成一个数组呢?数据插入到表中,但其插入被选择或高亮只,它不插入其他行项目的行项目。该行有类,当你点击它突出了一行。

how can I convert this into an array? The data inserts to the table but it inserts the row item that is selected or highlighted only, it doesn't inserts the other row items. the row has class that when you click it highlights the row.

case "Add":
        if(isset($_POST['Add'])){
                    $Addquery = "INSERT INTO tb_empgrocery (empgrocID, coopmemID , date_ordered, item_no, qty_ordered, unit_price, amount, date_delivered, qty_delivered, order_status, released_by) VALUES ('".$_POST['empgrocID']."', '".$login['is_coopmemID_kiosk']."', (NOW()), '".$_POST['itemNo']."', '".$_POST['orderqty']."', '".$_POST['unit_price']."', '".$_POST['amount']."', '".$_POST['date_delivered']."', '".$_POST['qty_delivered']."','".$_POST['order_status']."','".$_POST['released_by']."')";
                    mysql_query($Addquery, $con);
                    }
        break;

这是正确的?

case "Add":
            $_POST = array_map('addlashes', $_POST);
            $values = array();
                foreach ($_POST as $key => $value) {
                    $values[] = "('{$_POST['empgrocID']}', '{$login['is_coopmemID_kiosk']}', '{$_POST['(NOW())']}', '{$_POST['itemNo']}', '{$_POST['orderqty']}', '{$_POST['unit_price']}', '{$_POST['amount']}', '{$_POST['date_delivered']}', '{$_POST['qty_delivered']}', '{$_POST['order_status']}', '{$_POST['released_by']}')";
                }
                if(sizeof($values)) {
                    $query = "INSERT INTO tb_empgrocery (empgrocID, coopmemID , date_ordered, item_no, qty_ordered, unit_price, amount, date_delivered, qty_delivered, order_status, released_by) VALUES ".implode(',', $values);
                    $result = mysql_query($query, $con);
                }
        break;

在此先感谢

推荐答案

$ _ POST本身就是一个数组,你可以在你的表,只要提交数据密钥匹配您的表列插入数据。

$_POST is an array itself, you can insert data in your table as long as the post data keys match your table columns.

这篇关于如何将多个数据到一个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆