PHP,MYSQL插入每个办公室订购的产品数量

时间:2017-10-18 16:49:44

标签: php mysqli

我想请求帮助,了解如何保存每个办事处订购的每件产品的数量。我还想保存订购的每种产品的总量和总量。  到目前为止,唯一的工作是自动计算和产品和办公室的查询。 之后,下一个输出将回应所有产品,除了那些没有订购的产品。 抱歉:P

My database

My output so far

到目前为止我的代码

<html>
<head>
    <title>Project Procurement Management Plan</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
      <link href='assets/jquery/jquery-ui.min.css' type='text/css' rel='stylesheet' >

<script src="assets/jquery/jquery-3.2.1.min.js" type="text/javascript"></script>
<script src="assets/jquery/jquery-ui.min.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<script src="assets/jquery/pr_table.js"></script>
</head>
<body>
<form action = "ppmp.php" method="POST">
    <table border='2px' id='table' class='table' style="width:2800px">
        <thead>


            <tr>

                <th width="20"><div class="vertical">PREFIX</th>
                <th class="vertical"><div class="vertical">Stock #</th>
                <th class="vertical"><div class="vertical">Unit of Measure</th>
                <th width="400">Item Description</th>
                <th>PRICE</th>
                <th width="50px">UNIT <br>PRICE <br>Current Price</th>
                <th width="50px">UNIT PRICE X 1.10%<br>(Current Price x 1.10%)</th>
                <th></th>
                <th width="50px">Total No. of Users<br>(Office/s)</th>
                <?php
                $connection = mysqli_connect('localhost', 'root', ''); 
                    mysqli_select_db($connection,'thesis');

                    $query = "SELECT * FROM office_tbl"; 
                    $result = mysqli_query($connection,$query);



                    while($row = mysqli_fetch_array($result)){  
                        echo "<th class='vertical'><div class='vertical'>".$row['office_abb']."<br>".$row['office_id']."</th>";

                    }



                    mysqli_close($connection);
            ?>

                <th>TOTAL AMOUNT</th>           
            </tr>

        </thead>

        <tbody>
            <tr>
                <td colspan='6'></td>
                <td colspan='2'><strong>Total Employees

                <td style='width:40'><input type='text' style='width:63' value='0' id='input' class='total_qty' name='total_employees'></input></td>

                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input1' name='input1'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input2' name='input2'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input3' name='input3'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input4' name='input4'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input5' name='input5'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input6' name='input6'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input7' name='input7'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input8' name='input8'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input9' name='input9'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input10' name='input10'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input11' name='input11'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input12' name='input12'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input13' name='input13'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input14' name='input14'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input15' name='input15'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input16' name='input16'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input17' name='input17'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input18' name='input18'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input19' name='input19'></input></td>
                <td style='width:40'><input type='text' style='width:50' value='0' id='input' class='input20' name='input20'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input21' name='input21'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input22' name='input22'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input23' name='input23'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input24' name='input24'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input25' name='input25'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input26' name='input26'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input27' name='input27'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input28' name='input28'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input29' name='input29'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input30' name='input30'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input31' name='input31'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input32' name='input32'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input33' name='input33'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input34' name='input34'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input35' name='input35'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input36' name='input36'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input37' name='input37'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input38' name='input38'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input39' name='input39'></input></td>
                <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input40' name='input40'></input></td>


            </tr>

            <tr>
                <td colspan='4' align="center"><h2>01 - OFFICE SUPPLIES</strong>
                <td colspan= '3'></td>
                <td colspan='1'><strong>TOTAL QTY</td>
                <td colspan='40'></td>
            </tr>


            <?php
                $connection = mysqli_connect('localhost', 'root', ''); 
                    mysqli_select_db($connection,'thesis');

                    $query = "SELECT * FROM pro_tbl WHERE prefix = '1'"; 
                    $result = mysqli_query($connection,$query);

                    $index = 0;

                    while($row = mysqli_fetch_array($result)){  

                        echo "<tr id='tr'>
                            <td>". $row['prefix'] . 
                            "<td>". $row['Stock_Num'] . 
                            "</td></input><td>". $row['UOM'] . 
                            "</td><td>" . $row['Description'] . 
                            "</td><td type='text' name='price1'></td><td>". $row['UP_CP'] . 
                            "</td><td><input class='unit_price' value=".$row['UP_Percentage']."></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='total_qty' name='input1'></input></td>
                            <td><span class ='total_qty' id='total_qty'></span></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input1' name='input1'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input2' name='input2'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input3' name='input3'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input4' name='input4'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input5' name='input5'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input6' name='input6'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input7' name='input7'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input8' name='input8'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input9' name='input9'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input10' name='input10'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input11' name='input11'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input12' name='input12'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input13' name='input13'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input14' name='input14'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input15' name='input15'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input16' name='input16'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input17' name='input17'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input18' name='input18'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input19' name='input19'></input></td>
                            <td style='width:40'><input type='text' style='width:50' value='0' id='input' class='input20' name='input20'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input21' name='input21'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input22' name='input22'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input23' name='input23'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input24' name='input24'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input25' name='input25'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input26' name='input26'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input27' name='input27'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input28' name='input28'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input29' name='input29'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input30' name='input30'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input31' name='input31'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input32' name='input32'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input33' name='input33'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input34' name='input34'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input35' name='input35'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input36' name='input36'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input37' name='input37'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input38' name='input38'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input39' name='input39'></input></td>
                            <td style='width:40'><input type='text' style='width:40' value='0' id='input' class='input40' name='input40'></input></td>
                            <td>". $row['id'] ."</td>




                            <td style='width:40'><input type='text' style='width:140' value='0' id='input' class='total_amount' name='total_amount'></input></td>
                            </tr>"; 
                            $index++;
                    }



                    mysqli_close($connection);
            ?>

        </tbody>

        <tfoot>
            <tr>
                <td colspan ='2'><input value='Print' style='width:75' type="button" onclick="window.print()" />
                <td colspan ='1'><input value='Save' name='Save' style='width:75' type='submit'/>
                <td colspan ='1'><input name = "ppmp_no"></input>
            </tr>
        </tfoot>
    </table>
    </form>
</body>

<script>
    (function() {
"use strict";

$("table").on("keyup", "input", function() {
  var row = $(this).closest("tr");
  var input1 = parseFloat(row.find(".total_qty").val());
  var input2 = parseFloat(row.find(".unit_price").val());

  var total = input1 * input2;


  row.find(".total_amount").val(isNaN(total) ? "" : total.toFixed(2));
});

    })();
 </script>

1 个答案:

答案 0 :(得分:0)

首先,欢迎来到SO;下次,请告诉我们您尝试过的内容以及无法正常工作的内容等(例如,您确实陷入困境,包含您的代码)

那就是说,而不是为你编写代码,让我告诉你方法......

保存表单数据

如果没有更多相关信息,我会尝试一些假设的答案 -

  1. 创建数据库
  2.   

    如何创建数据库: http://php.net/manual/en/function.mysql-create-db.php

    1. 创建一个表来存储数量信息(当然,您将有其他表;因此可以根据需要创建,或者稍后再创建),并在数据库中使用需要存储的所有字段以及数量---假设“Stock#”是每个产品的唯一编号,至少,表格中需要stock_numberquantity个字段
    2.   

      如何制作表格&amp;查询信息等: http://php.net/manual/en/mysqli.query.php

      1. 假设您有“提交”或“确定”(等等......只要有一个按钮发布到SELF /另一个页面进行处理),以下是保存数据的方法:

        3.1在按下按钮的页面上,您首先需要 清理/验证数据(以便数量是数字而不是数字 - 等等,例如)

        3.2然后,您需要在使用的表中插入值 INSERT声明

        3.3(可选/但建议作为一种良好做法)在屏幕上显示 通知用户该条目已保存(或出现错误,如果 有任何)

      2.   

        以下是从开始到结束的第3步的一个很好的例子http://people.cs.ksu.edu/~hankley/d764/tut06/GopisettyPHP.html

        显示已保存的数据

        1. 导航至http://php.net/manual/en/mysqli.query.php链接,了解如何从上面步骤2中创建的表格中获取信息。

        2. 循环结果

        3.   

          mysql_fetch_assoc http://php.net/manual/en/function.mysql-fetch-assoc.php    mysql_fetch_array http://php.net/manual/en/function.mysql-fetch-array.php

          其他推荐

          如果您不熟悉规范化数据库,那么以下只是几个起点...... Google了解更多信息:

            

          数据库规范化简介: http://download.nust.na/pub6/mysql/tech-resources/articles/intro-to-normalization.html

               

          数据库规范化: http://rdowla.cidamon.com/Book/MySQL/normalization.php

               

          MySQL数据库规范化(Youtube视频): https://www.youtube.com/watch?v=JbjS7iujCbI

          希望这有帮助!