是否可以在表中运行两个单独的查询?

时间:2021-04-08 07:24:26

标签: php mysql

是否可以在一个表中运行两个查询?一个是表格本身,第二个是模态,第二个查询就像一个检查器,如果用户的请求状态已经被批准。

我的表的代码,<?php includes/repositoryretriever.php; ?> 是选择表中的所有内容并将其打印在表中的查询。

<table class="table table-striped table-hover table-condense" id="tbl_manageStudents">
                <thead>
                    <tr>
                        <th scope="col">Research UID</th>
                        <th scope="col">Research Title</th>
                        <th scope="col">Research Type</th>
                        <th scope="col">Action</th>
                    </tr>
                </thead>
                <tbody>
                        <?php
include 'includes/repositoryretriever.php';
?>
                </tbody>
            </table>

在表格内,正如你所看到的,我有一个 Action 操作按钮,有一个弹出模式,现在在弹出模式中,应该有一个动态按钮,可以识别用户是否已经得到了管理员的批准。

我在模态中的代码。 <?php includes/includes_checkRequestStatus.php ?> 是两个表的连接表

<div class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true" id="researchModal<?php echo
    $row["ID"]; ?>">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalCenterTitle"><?php echo $row['research_title']; ?></h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
      <h2>Research Abstract:</h2>
      <p> 
      <?php
      echo $row['research_description']; ?>
      </p>
      <h2>Author:</h2>
      <p><?php echo $row['research_author']; ?> </p>
      <div class="text-center">
      <?php 
        require_once 'includes/includes_checkRequestStatus.php';
      ?>
      </div>
      
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>

includes_checkRequestStatus.php

<?php
include 'includes/connection_operation.php';
$sql = "SELECT tbl_requestforms.ID, tbl_requestforms.request_id, tbl_repository.research_title, tbl_repository.research_tags, tbl_students.student_name, tbl_requestforms.request_status
FROM tbl_repository
JOIN  tbl_students
ON  tbl_repository.research_uid = tbl_students.student_id
JOIN tbl_requestforms ON tbl_requestforms.student_id=tbl_students.student_id
WHERE tbl_repository.research_uid = tbl_students.student_id;";
$query = mysqli_query($conn, $sql);

if ($query) {
    while ($row = mysqli_fetch_assoc($query)) {
        if($row['request_status'] == null){
            ?>
            <input type="submit" name="submit" id="submit" value="Delete" class="btn btn-danger" 
        data-toggle="modal" data-target="#deleteResearchModal<?php echo $row["ID"];?>">
            <?php 
        }
        else {
            
        }
    }
}
?>

repositoryretriever.php

<?php
include 'includes/connection_operation.php';
$sql = "SELECT * FROM tbl_repository";
$query = mysqli_query($conn, $sql);

if ($query) {
    while ($row = mysqli_fetch_assoc($query)) {
        ?>
        <tr>
    <th><?php echo $row['research_uid']; ?></th>
    <td><?php echo $row['research_title']; ?></td>
    <td><?php echo $row['research_tags']; ?></td>
    <td>
        <input type="submit" name="submit" id="submit" value="View" class="btn btn-info"
        data-toggle="modal" data-target="#researchModal<?php echo $row["ID"]; ?>">
    </td>
    </tr>
    <?php
include './helper/helper_researchModal.php';
    }
}
?>

但问题是,当我在模态中包含我的第二个查询时,即 <?php includes/includes_checkRequestStatus.php ?> 表只显示 1 行,尽管我在那里有 3 行。 任何建议或帮助将不胜感激。

0 个答案:

没有答案