2 回答
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');
?>
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');
?>
- 2 回答
- 0 关注
- 126 浏览
添加回答
举报