草庐IT

php - 在最后一行插入值

coder 2023-10-24 原文

如上图所示,我的 stock_transfer 表中有两个条目。 作为示例,我将插入两个不同的值来向您展示它的工作原理。 (产品 1 有 5 只股票,产品 2 有 10 只股票)

现在,当我尝试插入 Product 1 上剩余的请求库存并保留 Product 2 时,它将成功。

问题来了。当我尝试在我的 Product 2 上插入值(290 支股票)时,它会将值插入到 Product 1 表中。 谁能帮我这个?这是我的查询代码:

 if (isset($_POST['addCart']) && $_POST['addCart']=="Confirm Stock Transfer") {
 foreach($_POST['qtyBuy'] as $index=>$value){
 if($value > 0){

  $cartProd_id = $_POST['product_id'][$index];
  $cartProd_name = $_POST['product_name'][$index];
  $cartProd_date = $_POST['product_exp'][$index];
  $cartProd_desc = $_POST['product_desc'][$index];
  $cartProd_transid = $_POST['transfer_id'][$index];

  //Update stock_transfer requests
  $update_stock = "UPDATE stock_transfer SET stocks_transferred = stocks_transferred + $value WHERE transfer_id = $cartProd_transid;";
  $update_stockE = mysqli_query($connection, $update_stock);

这是我的代码:

<table class="table table-striped table-bordered table-hover results table-fixed table-condensed" id="example">
    <thead>
      <tr>
        <th>#</th>
        <th>Product Name</th>
        <th>Description</th>
        <th>Sell Price</th>
        <th>Expiry Date</th>
        <th>Instock</th>
        <th>Stocks Requested Remaining</th>
        <th>Stocks Transferred</th>
        <th>Quantity to Transfer</th>
      </tr>
    </thead>
    <tbody>
    <?php 

      $getReq = "SELECT * FROM stock_transfer INNER JOIN td_products ON stock_transfer.transfer_product_id = td_products.product_id WHERE stock_transfer.transfer_number = $tid AND stock_transfer.transfer_tobranch = '$capitalPrefix';";
      $getReqE = mysqli_query($connection, $getReq);

      while ($row = mysqli_fetch_array($getReqE)) {
        $transfer_id = $row['transfer_id'];
        $transfer_number = $row['transfer_number'];
        $transfer_status = $row['transfer_status'];
        $transfer_frombranch = $row['transfer_frombranch'];
        $transfer_tobranch = $row['transfer_tobranch'];
        $transfer_product_id = $row['transfer_product_id'];
        $transfer_quantity = $row['transfer_quantity'];
        $transfer_date = $row['transfer_date'];
        $stocks_transferred = $row['stocks_transferred'];

        $remainingStocks = $transfer_quantity - $stocks_transferred;

        $product_id = $row['product_id'];
        $product_name = $row['product_name'];
        $product_price = $row['sell_price'];
        $description = $row['description'];
        $quantity = $row['quantity'];
        $expiry_date = $row['expiry_date'];
        echo $transfer_id;

     ?>
        <tr>
          <td class="text-center"><?php echo $product_id; ?>
            <input type="hidden" name="product_id[]" value="<?php echo $product_id; ?>">
          </td>
            <input type="hidden" name="transfer_id[]" value="<?php echo $transfer_id; ?>">
          <td><?php echo $product_name; ?>
            <input type="hidden" name="product_name[]" value="<?php echo $product_name; ?>">
          </td>
          <td><?php echo $description; ?>
            <input type="hidden" name="product_desc[]" value="<?php echo $description; ?>">
          </td>
          <td>₱ <?php echo number_format($product_price, 2); ?></td>
          <td><?php echo $expiry_date; ?>
            <input type="hidden" name="product_exp[]" value="<?php echo $expiry_date; ?>">
          </td>
          <td><strong><?php echo $quantity; ?></strong></td>
          <td><?php echo $remainingStocks; ?></td>
          <td><?php echo $stocks_transferred; ?></td>
          <td>
            <?php if (!$remainingStocks == 0){ ?>
            <input type="number" name="qtyBuy[]" id="<?php echo "qtyBuy" . $b++; ?>" min="1" max="<?php echo $remainingStocks;?>">
            <?php } else{ ?>
              <i class="glyphicon glyphicon-check"></i> Completed
            <?php } ?>
          </td>
        </tr>
        <?php }?>
      </tbody>
    </table>

    <div class="form-group">
      <input type="submit" name="addCart" value="Confirm Stock Transfer" class="btn btn-info pull-right">
      <a href="stock_manage_requests.php" class="btn btn-warning pull-left">Back to Request List</a>
    </div>

标签

这是我的架构:

最佳答案

看这个:

  <td>
     <input type="number" name="qtyBuy[]" id="<?php echo "qtyBuy" . $b++; ?>" min="1" max="<?php echo $remainingStocks;?>" <?php echo ($remainingStocks == 0') ? 'Disabled=true' : '';?> value="0">
   </td>

关于php - 在最后一行插入值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40836900/

有关php - 在最后一行插入值的更多相关文章

  1. ruby - Hanami link_to 助手只呈现最后一个元素 - 2

    我是HanamiWorld的新人。我已经写了这段代码:moduleWeb::Views::HomeclassIndexincludeWeb::ViewincludeHanami::Helpers::HtmlHelperdeftitlehtml.headerdoh1'Testsearchengine',id:'title'hrdiv(id:'test')dolink_to('Home',"/",class:'mnu_orizontal')link_to('About',"/",class:'mnu_orizontal')endendendendend我在模板上调用了title方法。htm

  2. ruby - 如果它是标点符号,我怎么能从字符串中删除最后一个字符,在 ruby​​ 中? - 2

    啊,正则表达式有点困惑。我正在尝试删除字符串末尾所有可能的标点符号:ifstr[str.length-1]=='?'||str[str.length-1]=='.'||str[str.length-1]=='!'orstr[str.length-1]==','||str[str.length-1]==';'str.chomp!end我相信有更好的方法来做到这一点。有什么指点吗? 最佳答案 str.sub!(/[?.!,;]?$/,'')[?.!,;]-字符类。匹配这5个字符中的任何一个(注意,。在字符类中并不特殊)?-前一个字符或组

  3. ruby - 如何在 Ruby 字符串中插入项目符号字符? - 2

    我正在尝试创建一个带有项目符号字符的Ruby1.9.3字符串。str="•"+"helloworld"但是,当我输入它时,我收到有关非ASCII字符的语法错误。我该怎么做? 最佳答案 你可以把Unicode字符放在那里。str="\u2022"+"helloworld" 关于ruby-如何在Ruby字符串中插入项目符号字符?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/1195

  4. ruby - 在 ruby​​ 中使用自动创建插入数组 - 2

    我想知道是否可以通过自动创建数组来插入数组,如果数组不存在的话,就像在PHP中一样:$toto[]='titi';如果尚未定义$toto,它将创建数组并将“titi”压入。如果已经存在,它只会推送。在Ruby中我必须这样做:toto||=[]toto.push('titi')可以一行完成吗?因为如果我有一个循环,它会测试“||=”,除了第一次:Person.all.eachdo|person|toto||=[]#with1billionofperson,thislineisuseless999999999times...toto.push(person.name)你有更好的解决方案吗?

  5. Ruby - 删除文件中的最后一个字符? - 2

    看起来一定很简单,但我就是想不通。如何使用RubyIO删除文件的最后一个字符?我查看了deletingthelastlineofafile的答案使用Ruby但没有完全理解它,必须有更简单的方法。有什么帮助吗? 最佳答案 有File.truncate:truncate(file_name,integer)→0Truncatesthefilefile_nametobeatmostintegerbyteslong.Notavailableonallplatforms.所以你可以这样说:File.truncate(file_name,Fil

  6. ruby-on-rails - 在方法调用中插入 Ruby? - 2

    在我的用户模型中,我有一堆属性,例如is_foos_admin和is_bars_admin,它们决定允许用户编辑哪些类型的记录。我想干掉我的编辑链接,目前看起来像这样:'edit'ifcurrent_user.is_foos_admin?%>...'edit'ifcurrent_user.is_bars_admin?%>我想做一个帮助程序,让我传入一个foo或bar并返回一个链接来编辑它,就像这样:助手可能看起来像这样(这不起作用):defedit_link_for(thing)ifcurrent_user.is_things_admin?link_to'Edit',edit_poly

  7. ruby-on-rails - Ruby on Rails 的最后 20% - 2

    我是(相当)一位经验丰富的程序员,但对Ruby和RubyonRails完全陌生。RoR看起来很适合快速工作,特别是用于CRUD操作的自动屏幕生成。它确实能让您快速提高工作效率。问题是最后20%的工作,那时我必须完成我的申请。RoR公约不会妨碍我吗?因为不是每个数据库表都必须对所有用户可用,也不是所有用户都可以编辑所有列和/或所有行,而且View必须适应我网站的外观等。我知道RoR已成功用于现场,但在第一阶段烧毁后,如何在RoR中获得足够的速度以逃避重力。 最佳答案 我认为脚手架无法让您达到80%。脚手架很好,因为它向您展示了Rail

  8. arrays - 在一行中选择数组的第一个和最后一个元素 - 2

    我的任务是从数组中选择最高和最低的数字。我想我很清楚我想做什么,但只是努力以正确的格式访问信息以满足通过标准。defhigh_and_low(numbers)array=numbers.split("").map!{|x|x.to_i}array.sort!{|a,b|ba}putsarray[0,-1]end数字可能看起来像"80917234100",要通过,我需要输出"9234"。我正在尝试putsarray.first.last,但一直无法弄明白。 最佳答案 有Array#minmax完全满足您需要的方法:array=[80,

  9. Ruby 将对象插入现有的已排序对象数组 - 2

    我有以下现有的Dog对象数组,它们按age属性排序:classDogattr_accessor:agedefinitialize(age)@age=ageendenddogs=[Dog.new(1),Dog.new(4),Dog.new(10)]我现在想插入一条新的狗记录,并将它放在数组中的正确位置。假设我想插入这个对象:another_dog=Dog.new(8)我想把它插入到数组中,让它成为数组中的第三项。这是一个人为的示例,旨在演示我特别想如何将一个项目插入到现有的有序数组中。我意识到我可以创建一个全新的数组并重新对所有对象进行排序,但这不是我的目标。谢谢!

  10. ruby - 如何使用 Ruby 从 CSV 中删除一行 - 2

    给定以下CSV文件,您将如何删除列“foo”中包含单词“true”的所有行?Date,foo,bar2014/10/31,true,derp2014/10/31,false,derp我有一个可行的解决方案,但它需要制作一个辅助CSV对象csv_no_foo@csv=CSV.read(@csvfile,headers:true)#http://bit.ly/1mSlqfA@headers=CSV.open(@csvfile,'r',:headers=>true).read.headers#MakeanewCSV@csv_no_foo=CSV.new(@headers)@csv.eachd

随机推荐