显示申请人待审

时间:2017-10-25 07:03:16

标签: php html

enter image description here

我必须从数据库表调用count.php中取出值,我已经得到了值49.问题是如何插入到html中

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "hopeplace";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$sql = "SELECT COUNT(*) AS TOTAL_APPLICANT FROM applicant";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while ($row = mysqli_fetch_assoc($result)) {
        echo $row["TOTAL_APPLICANT"];
    }
} else {
    echo "0 results";
}

mysqli_close($conn);
?>

申请人待审的容器代码

<div class="content">
    <div class="row">
        <div class="col-xs-5">
            <div class="icon-big icon-danger text-center">
                <i class="ti-user"></i>
            </div>
        </div>
        <div class="col-xs-7">
            <div class="numbers">
                <p>Applicant Pending</p>
                <p>*this is the place where value need to be put*</p>
            </div>
        </div>
    </div>
    <div class="footer">
        <hr />

    </div>
</div>

2 个答案:

答案 0 :(得分:3)

您可以为一个变量赋值并在html中回显该变量

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "hopeplace";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
   die("Connection failed: " . mysqli_connect_error());
}
$count = 0;
$sql = "SELECT COUNT(*) AS TOTAL_APPLICANT FROM applicant";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
// output data of each row
   while($row = mysqli_fetch_assoc($result)) {
      $count = $row["TOTAL_APPLICANT"] ;
   }
} 
mysqli_close($conn);
?>

申请人待审容器的代码就像

&#13;
&#13;
<div class="content">
  <div class="row">
    <div class="col-xs-5">
      <div class="icon-big icon-danger text-center">
        <i class="ti-user"></i>
      </div>
    </div>
    <div class="col-xs-7">
      <div class="numbers">
        <p>Applicant Pending</p>
        <p>
          <?php echo $count; ?>
        </p>
      </div>
    </div>
  </div>
  <div class="footer">
    <hr />
  </div>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:2)

保存html&amp; php在同一个文件中或确保您的html代码保存为.php文件。因此,您的脚本将是 - <p><?php echo $total; ?></p><p><?= $total ?></p>