首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用用户名添加计数?

如何使用用户名添加计数?
EN

Stack Overflow用户
提问于 2018-12-09 04:53:34
回答 1查看 207关注 0票数 0

大家好,我正在做一个像服务这样的水龙头清单

现在,我只是想知道如何显示他们的用户名与创建和最后更新的列表与他们的总水龙头根据他们的用户名。

我有一张我喜欢的照片,我只是不知道如何让它工作:/

我喜欢它看起来像什么

用户数据库表

列表的数据库表

代码

代码语言:javascript
复制
<?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 } ?>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-12-09 05:16:07

更改查询并遵循以下代码

代码语言:javascript
复制
<?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 } ?>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53689504

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档