mysql 我应该怎么做,如果我的sqldata不显示在模态与引导?

eoigrqb6  于 2023-04-10  发布在  Mysql
关注(0)|答案(1)|浏览(157)

我试图做一个模态候选人配置文件,但我的SQL数据不显示。请帮助我,我一直试图解决这个问题,但我真的没有线索。我试图寻找方法来解决这个问题,但没有一个工作。我希望有人能帮助我,谢谢。
printscreen of the result I have

  • 这是我的代码 *
<!--button-->
<button data-bs-toggle="modal" data-bs-target="#profileModal" class="btn btn-primary" data-id="<?php echo $row['candidateID']?>">See profile</button>
<!--button-->

<!--Modal Profile -->
<div class="modal fade" id="profileModal">
  <div class="modal-dialog modal-dialog-scrollable">
    <div class="modal-content">
      
      

        <!-- Modal Header -->
        <div class="modal-header header-color text-white">

          <?php         
            include ('../dbconn.php');
            if(isset($_GET['id'])) {
            $id = $_GET['id'];
            $sql = "SELECT * FROM clg_candidates WHERE candidateID=$id";
            $result = $conn->query($sql);
                    
            if ($result->num_rows > 0) {
              while($row = $result->fetch_array()){
          ?>

          <h4 class="modal-title"><?php echo $row['name']?>'s Profile</h4>
          <img src="ACLCLOGO/sclogo2.png" class="sclogo_profile" alt="School Logo">
        </div>

        <!-- Modal body START-->
        <div class="modal-body">
            <img class="card-img-top modal-img " src="picture/<?php echo $row['picture']?>" alt="candidate image" style="width: 300px;">
            <br>
            <h4><strong><b><?php echo $row['position']?></b></strong></h4>
            <br>
          <div class="content-text">
            <div class="text-profile">
              <strong>Name:</strong> <?php echo $row['name']?><br>
              <strong>Party List:</strong> <?php echo $row['partyList']?><br>
              <strong>Year/Grade & Course/Strand:</strong> <?php echo $row['yearLvl']?> - <?php echo $row['course']?><br>
              <strong>Platform:</strong> <?php echo $row['platform']?> 
            </div>
          </div>
        
        
          <?php 
            }       
            }
            $conn->close();
            }
          ?> 

        </div>
         <!-- Modal body END-->

      <!-- Modal footer START-->
      <div class="modal-footer">
        <button type="button" class="btn btn-danger" data-bs-dismiss="modal">Close</button>
      </div>
      <!-- Modal footer END-->

      

    </div>
  </div>
</div>


<!-- Modal Profile END -->
dwbf0jvd

dwbf0jvd1#

试试这个代码。

<?php      
  $body = []; 
  include ('../dbconn.php');
  if(isset($_GET['id'])) {
    $id = $_GET['id'];
    $sql = "SELECT * FROM clg_candidates WHERE candidateID=$id LIMIT 1";
    $result = $conn->query($sql);
            
    if ($result->num_rows > 0) {
      $body = $result->fetch_array();
    }
    $conn->close();
  }
?>
<!--button-->
<button data-bs-toggle="modal" data-bs-target="#profileModal" class="btn btn-primary" data-id="<?php echo (!empty($body)) ? $body['candidateID'] : '' ?>">See profile</button>
<!--button-->

<!--Modal Profile -->
<div class="modal fade" id="profileModal">
  <div class="modal-dialog modal-dialog-scrollable">
    <div class="modal-content">
      <!-- Modal Header -->
      <div class="modal-header header-color text-white">
        <h4 class="modal-title"><?php echo (!empty($body)) ? $body['name']. "'s Profile" : "No profile found" ?> </h4>
        <img src="ACLCLOGO/sclogo2.png" class="sclogo_profile" alt="School Logo">
      </div>

      <!-- Modal body START-->
      <div class="modal-body">
        <?php
          if(!empty($body)) {
        ?>
        <img class="card-img-top modal-img " src="picture/<?php echo $body['picture']?>" alt="candidate image" style="width: 300px;">
        <br>
        <h4><strong><b><?php echo $body['user_type']?></b></strong></h4>
        <br>
        <div class="content-text">
          <div class="text-profile">
            <strong>Name:</strong> <?php echo $body['name']?><br>
            <strong>Party List:</strong> <?php echo $body['partyList']?><br>
            <strong>Year/Grade & Course/Strand:</strong> <?php echo $body['yearLvl']?> - <?php echo $body['course']?><br>
            <strong>Platform:</strong> <?php echo $body['platform']?> 
          </div>
        </div>
        <?php
          }else{
        ?>
        <br>
        <h4><strong><b>No Candidate found</b></strong></h4>
        <br>
        <?php
          }
        ?>
      </div>
      <!-- Modal body END-->

      <!-- Modal footer START-->
      <div class="modal-footer">
        <button type="button" class="btn btn-danger" data-bs-dismiss="modal">Close</button>
      </div>
      <!-- Modal footer END-->
    </div>
  </div>
</div>
<!-- Modal Profile END -->

相关问题