Mysql编辑用户已下达的订单 [英] Mysql edit users orders they have placed

查看:92
本文介绍了Mysql编辑用户已下达的订单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在通过一个订购系统,我已完成订单并且它进入数据库很好,但我很难想到如何让用户在插入后编辑订单。

Hi i'm working through an ordering system, i've got the placing an order done and its going into the database fine, but i'm struggling to think how to let the user edit the order once its been inserted.

这是我从页面获取订单并将其发送到PHP插入脚本的方式:

This is how i grab the order from the page and send it to a PHP insert script:

$('#submit').live('click',function(){ 

                    var postData = {};
                    $('#items tr').not(':first').each(function(index, value) {
                        var keyPrefix = 'data[' + index + ']';
                        postData[keyPrefix + '[supp_short_code]'] = $(this).closest('tr').find('.supp_short_code').text();
                        postData[keyPrefix + '[project_ref]'] = $(this).closest('tr').find('.project_ref').text();
                        postData[keyPrefix + '[om_part_no]'] = $(this).closest('tr').find('.om_part_no').text();
                        postData[keyPrefix + '[description]'] = $(this).closest('tr').find('.description').text();
                        postData[keyPrefix + '[quantity_input]'] = $(this).closest('tr').find('.quantity_input').val();
                        postData[keyPrefix + '[cost_of_items]'] = $(this).closest('tr').find('.cost_of_items').text();
                        postData[keyPrefix + '[cost_total_td]'] = $(this).closest('tr').find('.cost_total_td').text();
                    });

                $.ajax
                    ({
                    type: "POST",
                    url: "order.php",
                    dataType: "json",
                    data: postData,
                    cache: false,
                    success: function()
                        {
                            alert("Order Submitted");
                        }
                    });
            });

这是PHP插入:

if (isset($_POST['data']) && is_array($_POST['data'])) {
                foreach ($_POST['data'] as $row => $data) {
                    $result = mysql_query("INSERT INTO orders (id,order_id,project_ref,supp_short_code,om_part_no,description,quantity,cost_of_items,cost_total) VALUES('', '".$order_id."', '".$data['project_ref']."', '".$data['supp_short_code']."', '".$data['om_part_no']."', '".$data['description']."', '".$data['quantity_input']."', '".$data['cost_of_items']."', '".$data['cost_total_td']."') ") or die(mysql_error());
                }
            }

所以我知道这不是最干净的方式这样做,这就是为什么我正在努力找到一个让他们编辑订单的干净方法。我知道如何做更新查询,但事实上我已经用于每个循环和数组插入订单?任何人都可以从上面的代码中获得有关向用户呈现内容的任何建议吗?

So i'm aware this isnt the cleanest way to do it, so thats why i'm struggling to find a clean way to let them edit the order. I know how to do "Update" queries but its the fact that i've used for each loops and arrays to insert the order? Anyone have any advice from the code above on what to present to the user?

推荐答案

取决于您使用的框架(如果一个),只需为订单创建一个视图。您可以在其他页面上执行此操作,也可以通过ajax加载表单。无论哪种方式,表单看起来都是这样的:

Depending on the framework you're using (if one at all), just create a view for the order. You could either do this on another page or by loading a form via ajax. Either way, the form would look something like this:

<?php
    if(isset($_POST['submit']) && $_POST['submit'] == "Submit") {
        $database->update("orders",$_POST,$_POST['id']);
    }

    $order = $database->query(
        "select
            id,
            order_id,
            project_ref,
            supp_short_code,
            om_part_no,
            description,
            quantity,
            cost_of_items,
            cost_total
        from orders where id = ".$id);
?>

<form method="post" action="<?php echo basename($_SERVER['PHP_SELF']); ?>">
    <input type="text" name="id"                value="<?php echo $order['id']; ?>">
    <input type="text" name="order_id"          value="<?php echo $order['order_id']; ?>">
    <input type="text" name="project_ref"       value="<?php echo $order['project_ref']; ?>">
    <input type="text" name="supp_short_code"   value="<?php echo $order['supp_short_code']; ?>">
    <input type="text" name="om_part_no"        value="<?php echo $order['om_part_no']; ?>">
    <input type="text" name="description"       value="<?php echo $order['description']; ?>">
    <input type="text" name="quantity"          value="<?php echo $order['quantity']; ?>">
    <input type="text" name="cost_of_items"     value="<?php echo $order['cost_of_items']; ?>">
    <input type="text" name="cost_total"    value="<?php echo $order['cost_total']; ?>">
    <input type="submit" name="submit" value="Submit">
</form>

$ database对象的代码在这里:

The code for the $database object is here:

http://www.jtgraphic.net/code/database-object/

这篇关于Mysql编辑用户已下达的订单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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