【问题标题】:Display selected row on another page, on button click在另一页上显示选定的行,单击按钮
【发布时间】:2020-06-11 18:10:00
【问题描述】:

我有一个表格读出数据库的几列,每行都有一个编辑按钮。我要做的就是,当单击编辑按钮时,该行将在另一个页面中显示其所有列。任何帮助都会很棒。我知道这很简单,但我可以让它工作。我能够导航到下一页,但不确定如何携带特定行的 id 并将其读出。谢谢。

index. php

<form id="mainform" action="editFunding2.php">
  <div class='row'>
    <div class='col-12'>
      <div class='table table-responsive'>
        <table class='table table-striped table-bordered datatable active' id='grantTable'>
          <thead>
              <tr>
                <th>FP ID</th>
                <th>Short Title</th>
                <th>PI</th>
                <th>Department</th>
                <th>Funding Type</th>
                <th>Change Funding Type</th>
              </tr>
          </thead>
          <tbody>
            <?php
            //Foreach loop iterates through each column of $getallrows function
            foreach($allRows as $rowID => $rowInfo){ ?>
              <tr>
                <td><?php echo $rowInfo['fpID'];?></td>
                <td><?php echo $rowInfo['shortTitle'];?></td>
                <td><?php echo $rowInfo['PI'];?></td>
                <td><?php echo $rowInfo['Department'];?></td>
                <td><?php echo $rowInfo['fundingType'];?></td>
                <!--Create dynamic id -->
                <?php $rdDrop = "ddgrantType_".$rowInfo['fpID'];?>
                  <td>
                    <button type="submit" class="btn btn-danger" name="action" value='Change Funding Type'>Change Funding</button>
                  </td>
                </tr>
              <?php } ?>
            </tbody>
          </table>
        </div>
      </div>
    </div>
  </form>
My editFunding2.php page

  <div class='row'>
        <div class='col-12'>
          <div class='table table-responsive'>
            <table class='table table-striped table-bordered datatable active' id='grantTable'>
              <thead>
                  <tr>
                    <th>FP ID</th>
                    <th>Short Title</th>
                    <th>PI</th>
                    <th>Department</th>
                    <th>Division</th>
                    <th>Sponsor Name</th>
                    <th>Project Start</th>
                    <th>Project End</th>
                    <th>Funding Type</th>
                    <th>Yes/No</th>
                    <th>Proper Type If No</th>
                    <!-- <th>Exclusions</th>
                    <th>FP Durtation</th> -->
                    <th>Comment</th>
                  </tr>
                  </thead>
                  <tbody>
                    <?php
                    session_start();
                    $editRow = $_REQUEST['fpID'];
                    $mssql = mysqli_query("SELECT * FROM spacing.METADATA_WEBFORM WHERE FUNDING_PROPOSAL_ID = $fpID' ") or die (mysqli_error());
                    while($rowInfo = mysqli_fetch_array($mssql)) {
                   ?>
                      <tr>
                        <td><?php echo $rowInfo['fpID'];?></td>
                        <td><?php echo $rowInfo['shortTitle'];?></td>
                        <td><?php echo $rowInfo['PI'];?></td>
                        <td><?php echo $rowInfo['Department'];?></td>
                        <td><?php echo $rowInfo['Division'];?></td>
                        <td><?php echo $rowInfo['sponsorName'];?></td>
                        <td><?php echo $rowInfo['Date_Project_Start']->format('Y-m-d');?></td>
                        <td><?php echo $rowInfo['Date_Project_End']->format('Y-m-d');?></td>
                        <td><?php echo $rowInfo['fundingType'];?></td>
                      <?php } ?>
                        <!--Create dynamic id -->
                        <?php $rdDrop = "ddgrantType_".$rowInfo['fpID'];?>
                      <td>
                        <div class="form-check">
                          <label class="form-check-label">
                            <input type="radio" class='form-check-input' name="rdGrant[<?php echo $rowInfo['fpID'];?>]" value="Yes" id="rdYes" onclick="disable('<?php echo $rdDrop;?>')" checked/> Yes
                          </label>
                        </div>
                        <div class="form-check">
                          <label class="form-check-label">
                              <input class='form-check-input' type="radio" name="rdGrant[<?php echo $rowInfo['fpID'];?>]" value="No" id="rdNo" onclick="enable('<?php echo $rdDrop;?>')"/> No
                          </label>
                        </div>
                      </td>
                      <td>
                        <div class="dropdown">
                          <select class='form-control' name="ddgrantGroup[<?php echo $rowInfo['fpID'];?>]" id="<?php echo $rdDrop;?>" disabled>
                            <option value=''>Select Proper Funding Type</option>
                            <option value="Corporate Sponsor">Corporate Sponsor</option>
                            <option value="Federal">Federal</option>
                            <option value="Foundation Selected">Foundation Selected</option>
                            <option value="Internally Funded">Internally Funded</option>
                            <option value="State/Local">State/Local</option>
                          </select>
                        </div>
                      </td>
                      <td>
                        <div class="comment">
                          <textarea class="form-control" aria-label="With textarea" name="grantComment[<?php echo $rowInfo['fpID'];?>]" id="grantComment" placeholder="Comments"></textarea>
                        </div>
                      </td>
                    </tr>
                </tbody>
              </div>
            </div>
          </div>
        <div class='row'>
          <div class='col-12 text-right'>
            <button type="submit" class="btn btn-secondary formsubmitbttn" name="action" value='save'>Save</button>
            <button type="submit" class="btn btn-primary formsubmitbttn" name="action" value='complete'>Complete and Save</button>
          </div>
        </div>
    </div>

【问题讨论】:

标签: php mysql forms session button


【解决方案1】:

将您的按钮更改为

<a href="editFunding2.php?id=<?= $rowInfo['fpID']; ?>">My Link to xx</a>

在editFunding2.php中:

$editRow = $_GET['id'];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-24
    • 2018-01-06
    • 1970-01-01
    • 1970-01-01
    • 2013-06-23
    相关资源
    最近更新 更多