亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 PHP 儀表板中顯示數據庫記錄計數

在 PHP 儀表板中顯示數據庫記錄計數

PHP
POPMUISE 2023-07-21 15:56:19
我需要在我的 SQLtable“醫生”中顯示記錄(行)的“計數”。此計數必須出現在我的儀表板頁面上醫生總數的以下元素中這是我的儀表板頁面的index.php    <?php$con = mysqli_connect("localhost","root","","hospital_db");$result = mysqli_query($con,"SELECT * FROM doctors");$rows = mysqli_num_rows($result);  $content = '<div class="row">        <div class="col-lg-3 col-xs-6">          <!-- small box -->          <div class="small-box bg-aqua">            <div class="inner">             <h3><?php echo '.$rows.';?></h3>              <p>Doctors</p>            </div>            <div class="icon">              <i class="ion ion-bag"></i>            </div>            <a href="http://localhost/medibed/doctor" class="small-box-footer">View Doctors <i class="fa fa-arrow-circle-right"></i></a>          </div>        </div>        <!-- ./col -->      </div>';  include('../master.php');?>
查看完整描述

2 回答

?
慕姐8265434

TA貢獻1813條經驗 獲得超2個贊

您應該在新的 php 版本中使用 mysqli 對象嘗試以下代碼


首先建立連接就像


<?php


$con = mysqli_connect("localhost","my_user","my_password","my_db");


$result = mysqli_query($con,"SELECT * FROM doctors");

$rows = mysqli_num_rows($result);

echo "There are " . $rows . " rows in my table.";


  $content = '<div class="row">

        <div class="col-lg-3 col-xs-6">

          <!-- small box -->

          <div class="small-box bg-aqua">

            <div class="inner">

              *<h3><?php echo "$rows"; } ?></h3>*


              <p>Doctors</p>

            </div>

            <div class="icon">

              <i class="ion ion-bag"></i>

            </div>

            <a href="http://localhost/medibed/doctor" class="small-box-footer">View Doctors <i class="fa fa-arrow-circle-right"></i></a>

          </div>

        </div>

        <!-- ./col -->


      </div>';

  include('../master.php');

?>


查看完整回答
反對 回復 2023-07-21
?
蠱毒傳說

TA貢獻1895條經驗 獲得超3個贊

如果您只需要計數那么為什么不在查詢中使用聚合函數 count(*) 呢?這對你有更好的幫助。在 h3 標記的代碼中,您可以直接連接字符串,而不是再次使用 php 代碼。這可能看起來更好并且是結構化的形式。


嘗試這個:


<?php

$con = mysqli_connect("localhost","my_user","my_password","my_db");

$result = mysqli_query($con,"SELECT count(*) as total_rows FROM doctors");

$rows = $result->total_rows;

echo "There are " . $rows . " rows in my table.";

  $content = '<div class="row">

        <div class="col-lg-3 col-xs-6">

          <!-- small box -->

          <div class="small-box bg-aqua">

            <div class="inner">

          *<h3>'.$rows.'</h3>*

          <p>Doctors</p>

        </div>

        <div class="icon">

          <i class="ion ion-bag"></i>

        </div>

        <a href="http://localhost/medibed/doctor" class="small-box-footer">View Doctors <i class="fa fa-arrow-circle-right"></i></a>

      </div>

    </div>

    <!-- ./col -->

  </div>';

include('../master.php');

?>


查看完整回答
反對 回復 2023-07-21
  • 2 回答
  • 0 關注
  • 166 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號