Javascript 模态循环不正确

Javascript 模态循环不正确,javascript,php,html,mysql,Javascript,Php,Html,Mysql,尝试将我的模态添加到我的表中,我已经在循环数据库中的数据,但是模态只从循环中获取第一个数据,而表则完美地循环。如何使模态适当地循环,并希望详细了解我缺少了什么 多维数组可以工作吗?或者不应该在表中调用模态?尝试了最后一点,但也不起作用 <div class="table100"> <table id="p" class="table table-bor

尝试将我的模态添加到我的表中,我已经在循环数据库中的数据,但是模态只从循环中获取第一个数据,而表则完美地循环。如何使模态适当地循环,并希望详细了解我缺少了什么

多维数组可以工作吗?或者不应该在表中调用模态?尝试了最后一点,但也不起作用

                  <div class="table100">

                    <table id="p" class="table table-bordered" style="width:100%">
                      <thead>
                        <?php
                        $que = mysqli_query($connection, "SELECT * FROM account WHERE account_no = '$acc_no' && client_id ='$id'");
                        $q = mysqli_fetch_array($que);
                        $acc_id = $q['id'];
                        $result = mysqli_query($connection, "SELECT * FROM account_transaction WHERE (account_no = '$acc_no' && int_id = '$sessint_id') && (transaction_date BETWEEN '$std' AND '$endx') ORDER BY transaction_date ASC");
                        ?>
                        <tr class="table100-head">
                          <th class="column1">Transaction-Date</th>
                          <th class="column2">Value Date</th>
                          <th class="column3">Reference</th>
                          <th class="column4">Debits(&#8358;)</th>
                          <th class="column5">Credits(&#8358;)</th>
                          <th class="column6">Balance(&#8358;)</th>
                          <th></th>
                        </tr>
                      </thead>
                      <tbody>
                        <?php if (mysqli_num_rows($result) > 0) {
                          while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
                            $nxtbal = $row["running_balance_derived"];
                        ?>
                            <tr>
                              <!-- <td></td> -->
                              <td class="column1"><?php echo $row["transaction_date"]; ?></td>
                              <td class="column2"><?php echo $row["created_date"]; ?></td>
                              <?php
                              if ($row["transaction_type"] == "") {
                                $desc = "Deposit";
                              } else if ($row["transaction_type"] == "") {
                                $desc = "Withdrawal";
                              } else if ($row["transaction_type"] == "loan_disbursement") {
                                $desc = "Loan Disbursment";
                              } else if ($row["transaction_type"] == "percentage_charge") {
                                $desc = $row["description"];
                              } else if ($row["transaction_type"] == "flat_charge") {
                                $desc = $row["description"];
                              } else {
                                $desc = $row["description"];
                              }
                              ?>
                              <td class="column3"><?php echo $desc; ?></td>
                              <td class="column4"><?php echo number_format($row["debit"], 2); ?></td>
                              <td class="column5"><?php echo number_format($row["credit"], 2); ?></td>
                              <?php
                              // $newnext = mysqli_query($connection, "SELECT transaction_date, running_balance_derived, RunningTotal = SUM(running_balance_derived) AS OVER (ORDER BY transaction_date ROWS UNBOUNDED PRECEDING) FROM account_transaction WHERE account_id = '$acc_id' && (int_id = $sessint_id && branch_id = '$branch') && (transaction_date BETWEEN '$std' AND '$endx') ORDER BY transaction_date ASC");
                              // $mink = mysqli_fetch_array($newnext);
                              // $qwe = $mink["running_balance_derived"];
                              ?>
                              <td class="column6"><?php echo  number_format($nxtbal, 2); ?></td>
                              <td>
                                <a href="" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">Edit</a>
                                <!-- Button trigger modal -->

                                <!-- POP UP BEGINS -->

                                <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                                  <div class="modal-dialog" role="document">
                                    <div class="modal-content">
                                      <div class="modal-header">
                                        <h3 class="modal-title" id="exampleModalLabel">Reverse Transaction</h3>
                                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                          <span aria-hidden="true">&times;</span>
                                        </button>
                                      </div>
                                      <div class="modal-body">
                                        <form action="../functions/transactions/reversal.php" method="POST">
                                          <div class="col-md-12">
                                            <div class="form-group">
                                              <label class="bmd-label-floating" for="">ID: </label>
                                              <input class="form-control" type="number" name="id" placeholder="" readonly value="<?php echo $row["id"]; ?>">
                                            </div>
                                          </div>
                                          <div class="col-md-12">
                                            <div class="form-group">
                                              <label class="bmd-label-floating" for="">Account_no: </label>
                                              <input class="form-control" type="text" name="account_number" placeholder="" readonly value="<?php echo $row["account_no"]; ?>">
                                            </div>
                                          </div>
                                          <div class="col-md-12">
                                            <div class="form-group">
                                              <label class="bmd-label-floating" for="">Date: </label>
                                              <input class="form-control" type="date" name="transaction_date" placeholder="" readonly value="<?php echo $row["transaction_date"]; ?>">
                                            </div>
                                          </div>
                                          <div class="col-md-12">
                                            <div class="form-group">
                                              <label class="bmd-label-floating" for="">Amount:</label>
                                              <input class="form-control" type="number" name="amount" placeholder="" readonly value="<?php echo $row["amount"]; ?>">
                                            </div>
                                          </div>
                                          <div class="col-md-12">
                                            <div class="form-group">
                                              <label class="bmd-label-floating" for="">Receipt Number</label>
                                              <input class="form-control" type="number" placeholder="" readonly value="<?php echo $row["transaction_id"]; ?>">
                                            </div>
                                          </div>

                                          <button type="button" type="submit" class="btn btn-primary">Reverse</button>
                                        </form>
                                      </div>
                                      <div class="modal-footer">
                                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                                      </div>
                                    </div>
                                  </div>
                                </div>

                                <!-- POP UP ENDS -->
                              </td>
                            </tr>
                        <?php
                          }
                        } 
                        ?>
                        <!-- <th></th> -->
                      </tbody>
                    </table>
                  </div>
                </div>
              </div>
            </div>
          </div>


模态id对于所有模态都是相同的,所以它只会触发一个模态。请更改并将模式置于循环之外,并传递事件上的数据,或通过自动生成的id更改模式id以使其唯一。

所有模式的模式id都相同,因此它将只触发一个。请更改并将模式放在循环之外,并传递事件的数据,或者通过自动生成的id更改模式id以使其唯一。

正如@keerthi Vijay提到的,我遇到的问题是模式的id,下面是如何排序的代码示例

<td>
                                <a href="" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal<?php echo $row["id"]; ?>">Edit</a>
                                <!-- Button trigger modal -->

                                <!-- POP UP BEGINS -->

                                <div class="modal fade" id="exampleModal<?php echo $row["id"]; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                                  <div class="modal-dialog" role="document">
                                    <div class="modal-content">
                                      <div class="modal-header">
                                        <h3 class="modal-title" id="exampleModalLabel">Reverse Transaction</h3>
                                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                          <span aria-hidden="true">&times;</span>
                                        </button>
                                      </div>
                                      <div class="modal-body">
                                        <form action="../functions/transactions/reversal.php" method="POST">
                                          <div class="col-md-12">
                                            <div class="form-group">
                                              <label class="bmd-label-floating" for="">ID: </label>
                                              <input class="form-control" type="number" name="id" placeholder="" readonly value="<?php echo $row["id"]; ?>">
                                            </div>
                                          </div>
                                          <div class="col-md-12">
                                            <div class="form-group">
                                              <label class="bmd-label-floating" for="">Account_no: </label>
                                              <input class="form-control" type="text" name="account_number" placeholder="" readonly value="<?php echo $row["account_no"]; ?>">
                                            </div>
                                          </div>
                                          <div class="col-md-12">
                                            <div class="form-group">
                                              <label class="bmd-label-floating" for="">Date: </label>
                                              <input class="form-control" type="date" name="transaction_date" placeholder="" readonly value="<?php echo $row["transaction_date"]; ?>">
                                            </div>
                                          </div>
                                          <div class="col-md-12">
                                            <div class="form-group">
                                              <label class="bmd-label-floating" for="">Amount:</label>
                                              <input class="form-control" type="number" name="amount" placeholder="" readonly value="<?php echo $row["amount"]; ?>">
                                            </div>
                                          </div>
                                          <div class="col-md-12">
                                            <div class="form-group">
                                              <label class="bmd-label-floating" for="">Receipt Number</label>
                                              <input class="form-control" type="number" placeholder="" readonly value="<?php echo $row["transaction_id"]; ?>">
                                            </div>
                                          </div>

                                          <button type="button" type="submit" class="btn btn-primary">Reverse</button>
                                        </form>
                                      </div>
                                      <div class="modal-footer">
                                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                                      </div>
                                    </div>
                                  </div>
                                </div>

                                <!-- POP UP ENDS -->
                              </td>


正如@keerthi Vijay提到的,我遇到的问题是modal的ID,下面是一个关于如何解决这个问题的代码示例

<td>
                                <a href="" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal<?php echo $row["id"]; ?>">Edit</a>
                                <!-- Button trigger modal -->

                                <!-- POP UP BEGINS -->

                                <div class="modal fade" id="exampleModal<?php echo $row["id"]; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                                  <div class="modal-dialog" role="document">
                                    <div class="modal-content">
                                      <div class="modal-header">
                                        <h3 class="modal-title" id="exampleModalLabel">Reverse Transaction</h3>
                                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                          <span aria-hidden="true">&times;</span>
                                        </button>
                                      </div>
                                      <div class="modal-body">
                                        <form action="../functions/transactions/reversal.php" method="POST">
                                          <div class="col-md-12">
                                            <div class="form-group">
                                              <label class="bmd-label-floating" for="">ID: </label>
                                              <input class="form-control" type="number" name="id" placeholder="" readonly value="<?php echo $row["id"]; ?>">
                                            </div>
                                          </div>
                                          <div class="col-md-12">
                                            <div class="form-group">
                                              <label class="bmd-label-floating" for="">Account_no: </label>
                                              <input class="form-control" type="text" name="account_number" placeholder="" readonly value="<?php echo $row["account_no"]; ?>">
                                            </div>
                                          </div>
                                          <div class="col-md-12">
                                            <div class="form-group">
                                              <label class="bmd-label-floating" for="">Date: </label>
                                              <input class="form-control" type="date" name="transaction_date" placeholder="" readonly value="<?php echo $row["transaction_date"]; ?>">
                                            </div>
                                          </div>
                                          <div class="col-md-12">
                                            <div class="form-group">
                                              <label class="bmd-label-floating" for="">Amount:</label>
                                              <input class="form-control" type="number" name="amount" placeholder="" readonly value="<?php echo $row["amount"]; ?>">
                                            </div>
                                          </div>
                                          <div class="col-md-12">
                                            <div class="form-group">
                                              <label class="bmd-label-floating" for="">Receipt Number</label>
                                              <input class="form-control" type="number" placeholder="" readonly value="<?php echo $row["transaction_id"]; ?>">
                                            </div>
                                          </div>

                                          <button type="button" type="submit" class="btn btn-primary">Reverse</button>
                                        </form>
                                      </div>
                                      <div class="modal-footer">
                                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                                      </div>
                                    </div>
                                  </div>
                                </div>

                                <!-- POP UP ENDS -->
                              </td>


感谢您对@Dharman的专业意见,但这是为了测试目的。非常感谢您的投入。感谢您@Dharman的专业投入,但这是为了测试目的。我们仍然非常感谢您的意见,谢谢。