[英]how to add count with username?
大家好,我正在列出类似Service的水龙头列表
现在我只是想知道如何显示用户名以及创建的和最近更新的列表,以及基于用户名的水龙头总数
我得到了一张我喜欢的照片,但是我不知道如何使它起作用:/
用户的数据库表
列表的数据库表
编码
<?php
$sql = "SELECT * FROM list ";
$result = mysqli_query($link, $sql);
if( $result )
while($user = mysqli_fetch_assoc($result)) {
?>
<table class="table table-striped" id="faucetlist" width="100%" cellspacing="0">
<thead>
<tr>
<th><center>Faucetlist</center></th>
<th><center>Created</center></th>
<th><center>Last updated</center></th>
<th><center>faucets</center></th>
</tr>
</thead>
<tr>
<td><center><?php echo $user["username"]; ?></center></td>
<td><center><?php echo date('l jS F Y' , strtotime($user['Published']));?></center></td>
<td><center><?php echo date('h:i A' , strtotime($user['last_update']));?> </center></td>
<td><center>FAUCETS COUNT GO HERE </center></td>
</table>
<?php } ?>
更改您的查询并遵循此代码
<?php
$sql = "SELECT list.*,count(username) as faucet FROM list GROUP BY username";
$result = mysqli_query($link, $sql);
if( $result )
while($user = mysqli_fetch_assoc($result)) {
?>
<table class="table table-striped" id="faucetlist" width="100%" cellspacing="0">
<thead>
<tr>
<th><center>Faucetlist</center></th>
<th><center>Created</center></th>
<th><center>Last updated</center></th>
<th><center>faucets</center></th>
</tr>
</thead>
<tr>
<td><center><?php echo $user["username"]; ?></center></td>
<td><center><?php echo date('l jS F Y' , strtotime($user['Published']));?></center></td>
<td><center><?php echo date('h:i A' , strtotime($user['last_update']));?> </center></td>
<td><center>FAUCETS COUNT GO HERE </center><?php echo $user['faucet']; ?></td>
</table>
<?php } ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.