如何用用户名添加计数?

时间:2018-12-09 04:53:35

标签: php mysqli

大家好,我正在制作“服务”之类的水龙头清单

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

我得到了一张我喜欢的照片,并且 我什么都没有 提示如何使其工作:/

我喜欢它看起来像什么 database table for list

用户的数据库表

what I like it to look like

列表的数据库表

database table for users

代码

<?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 } ?>

1 个答案:

答案 0 :(得分:0)

更改查询并遵循此代码

<?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 } ?>