drwo2014 2016-11-10 16:41
浏览 44
已采纳

我无法将数据显示代码中的变量传递给另一个数据库代码(这与数据库连接)

I retrieve data from the database and present some data in text boxes, so that user can edit them. But there are multiple rows that user can edit. In order to get the number of records present to the user, I have used a variable called count. But I cant use that variable in the php database code.

part of data display code

 while($row = mysqli_fetch_array($result)){
                        echo '<form action = "UpdateItem.php" method="post">';
                        echo "<tr>";

                            echo "<td>" . $row['item_id'] . "</td>"; echo"<td ></td>";
                            $id[] = $row['item_id'];

                            echo "<td>" . $row['buyingPrice'] . "</td>";echo"<td></td>";
                            $sellingPrice = $row['sellingPrice'];
                            echo "<td>"."<input type ='text' name = \"sellingPrice".$count."\" value ='".$sellingPrice."'>"."</td>";
                            $stockQty = $row['stockQty'];
                            echo "<td>"."<input type ='text' name = \"stockQty".$count."\" value ='".$stockQty."'>"."</td>";
                            $count = $count + 1;
                     echo "</td>";
                        echo "</tr>";                     
                    }

                    echo "</table>";
                    ?>
                    <div id="">
                    <input type="submit" class="myButton" id="btnManageStockUpdate" name="btnManageStockUpdate" value="Update"  />
                    </div>

                    <?php

                    echo "</form>";

php database code

           echo ("SellingPrice".$x);
            $sellingPrice = $_POST['sellingPrice'.$x];

            $stockQty = $_POST['stockQty'.$x];                

            $sql = "UPDATE item SET sellingPrice = $sellingPrice,stockQty = $stockQty WHERE item_id = $id[$x]";
            $result = mysqli_query($dbcon,$sql);
} 
 }
?>
  • 写回答

1条回答 默认 最新

  • doudi5291 2016-11-10 17:17
    关注

    create a hidden input field with name count and pass your count variable to it

    <input type="hidden" value="<?php $count?>" name="count">
    

    so at the end of the loop it will store the final count which you can use it to iterate a for loop in your php database code.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型