PHP MYSQL AJAX实时更新​​

时间:2018-11-26 07:57:18

标签: php jquery mysql ajax

screenshots of database structure and pages只是将链接添加到图像中。.

我只是一个新手,我的模拟系统存在一些问题,非常需要专家的帮助。

请对我好一点,因为我只在计算机上使用某些辅助技术,例如放大镜和屏幕阅读器。

在将某些特定值输入到出库和currentcount字段并生成列SOLD时,如何自动扣除我的initialcount字段上的值有问题。

我要实现的目标是,如果用户在上述字段中输入一些值(拉出和currentcount),则出售的字段应根据用户键入的数字自动生成,我打算使用该公式就像这样:

currentcount = initialcount-提取-出售。.

所以要用语言解释一下,列currentcount的值将是initialcount减去提取的产品再减去出售的产品。.

但是 用户只能填写拉出,不良订单,拉出和当前计数的行以保持系统的完整性。 我已经为这个模拟库存系统加入了3个数据库表,即产品清单,库存和库存。在点击我尚未添加的按钮后,库存表的最终值应保存到库存数据库表中。  我目前有以下相关代码。

当我有我所拍照片的链接时,可以直观地解释我所拥有的以及我想要达到的目标。

该字段的initialcount从我的库存数据库中获取记录,因此数据库库存不断更新。.

然后单击“保存库存”按钮(再次没有添加),整个列currentcount中的值应传输到column initialcount中。

就像削减列的当前计数并将其粘贴到下一个清单的列的初始计数的过程一样。

这就是我到目前为止所拥有的..

      <?php
  require_once 'config.php';
  $initialcount = $initialcount ?? '';
  $forpullout = $forpullout ?? '';
  $badorder = $badorder ?? '';
  $pulledout = $pulledout ?? '';
  $sold = $sold ?? '';
  $currentcount = $currentcount ?? '';
  $grosssale = $grosssale ?? '';

  $sql = "SELECT b.id,b.brand,b.wgtvol,b.unit,b.generic,b.grosssale,i.currentcount,m.initialcount,m.forpullout,m.badorder,m.pulledout,m.sold,m.sales,m.author,m.total FROM (productslist AS b LEFT JOIN stocks AS i ON b.id=i.id AND i.entryid=(SELECT MAX(entryid) FROM stocks WHERE id=b.id)) LEFT JOIN inventory AS m ON m.id=b.id";
      if($result = mysqli_query($link, $sql)){
    if(mysqli_num_rows($result) > 0){
  echo "<table style='background: #FAFAFA;' class='table table-striped'>";
  echo "<thead>";
  echo "<tr>";
  echo "<th class='hidden'>Product ID</th>";
  echo '<th class="m1-center-text head-up dg-bg w-fc product-container"> product </th>';
  echo '<th class="head-up-sm count-container xdg-bg w-fc m1-center-text"> initial<br>Count </th>';
  echo '<th class="head-up-sm count-container dr-bg w-fc m1-center-text"> for<br>pull<br>out </th>';
  echo '<th class="head-up-sm count-container dr-bg w-fc m1-center-text"> bad<br>order </th>';
  echo '<th class="head-up-sm count-container xdg-bg w-fc m1-center-text"> pulled<br>out</th>';
  echo '<th class="head-up-sm count-container b-bg w-fc m1-center-text product-container"> sold </th>';
  echo '<th class="hidden head-up-sm count-container b-bg w-fc m1-center-text product-container"> gs </th>';
  echo '<th class="head-up-sm count-container rb-bg w-fc m1-center-text product-container"> current<br>count </th>';
  echo '<th class="head-up-sm count-container dg-bg w-fc m1-center-text product-container"> gross<br>sale </th>';
  echo "<th class='hidden-col center-text'>Sell<br>Price</th>";
  echo "<th class='hidden-col center-text'>Gross<br>Sale</th>";
  echo '<th class="hidden-col center-text">Date Added<br>(Year-Month-Day-Time)</th>';
  echo "</tr>";
  echo "</thead>";
  echo "<tbody>";
        while($row = mysqli_fetch_array($result)){
  echo "<tr>";
  echo "<td class='hidden-col'>" . $row['id'] . "</td>";
  echo "<td class='lg-text'> " . $row['brand'] . "-" . $row['wgtvol'] . "" . $row['unit'] . " </td>";
  echo "<td id='initialcount' name='initialcount' class='center-text lg-text'>" . $row['currentcount'] . "</td>";
  echo "<td contenteditable id='forpullout' name='forpullout' class='decimal center-text lg-text'>" . $row['forpullout'] . "</td>";
  echo "<td contenteditable id='badorder' name='badorder' class='decimal center-text lg-text'>" . $row['badorder'] . "</td>";
  echo "<td contenteditable id='pulledout' name='pulledout' class='decimal center-text lg-text'>" . $row['pulledout'] . "</td>";
  echo "<td class='center-text lg-text'>" . $row['sold'] . "</td>";
  echo "<td id='grosssale' name='grosssale' class='hidden center-text lg-text'>" . $row['grosssale'] . "</td>";
  echo "<td contenteditable id='currentcount' name='currentcount' class='decimal 
  center-text lg-text'>" . $row['currentcount'] . "</td>";
  echo "</tr>";
  }
        mysqli_free_result($result);
  } else{
  echo "<p class='lead'><em>No records were found.</em></p>";
  }
  } else{
  echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
  }
  mysqli_close($link);
  ?>
  <?php
  require_once 'config.php';
   if($_SERVER["REQUEST_METHOD"] == "POST"){

   $sql = "INSERT INTO inventory (initialcount, forpullout, badorder, pulledout, sold, currentcount, sellprice, grosssales) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
     if($stmt = mysqli_prepare($link, $sql)){
    mysqli_stmt_bind_param($stmt, "ssssssss", $param_initialcount, $param_forpullout, $param_badorder, $param_pulledout, $param_sold, $param_cfurrentcount, $param_grosssales);
        $param_initialcount = $row_initialcount;
        $param_forpullout = $row_forpullout;
        $param_badorder = $row_badorder;
        $param_pulledout = $row_pulledout;
        $param_sold = $row_sold;
        $param_currentcount = $row_currentcount;
        $param_grosssales = $row_grosssales;
  if(mysqli_stmt_execute($stmt)){
  header("location: index.php");
  exit();
        } else{
            echo "Something went wrong. Please try again later.";
        }
    mysqli_stmt_close($stmt);
  }
  mysqli_close($link);
  }
  ?>
  <script
    src="https://code.jquery.com/jquery-3.3.1.js"
    integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
    crossorigin="anonymous"></script>

  </head>
  <body>
  <script>
  $('.decimal').keypress(function(e){
      var valid_keys = '0123456789.';
              function contains(needle, haystack) {
                  return haystack.indexOf(needle) > -1;
   }
        if(!contains(e.key, valid_keys) && e.key.length === 1 || (e.key == '.' && contains('.', $(this).val()))) {
            e.preventDefault();
        } 
  });
  </script>

  <script type="text/javascript">
  $(document).ready(function() {
    $(document).ajaxError(function (e, jqXHR, status, error) {
      console.log('error: ' + error);
    });
    $('#currentcount').on("input", function() {
      var tdVal = $(this).val();
      var hiddenInputElem = $('input[type=hidden]').val();
      if(inputVal.length) {
        $.getJSON("product-current-count.php", {id: hiddenInputElem}, function(data) {
          $('#currentcount').val(data.total = parseInt(inputVal));
        });
   }
  });
  });
  </script>
  </body>
  </html>

请教我如何输出想要得到的信息。.谢谢。.

0 个答案:

没有答案