在php Jmeter 板中显示db记录的计数

sqyvllje  于 2021-07-24  发布在  Java
关注(0)|答案(2)|浏览(321)

我需要在sqltable“doctors”中显示记录(行)的“count”。此计数必须出现在我的 Jmeter 板页面的以下元素中,以显示医生总数
这是我的 Jmeter 板页面的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');
?>
8fq7wneg

8fq7wneg1#

您应该在新的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');
?>
jv4diomz

jv4diomz2#

如果您只需要count,那么为什么不在查询中使用聚合函数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');
?>

相关问题