首页 > 解决方案 > 检查当前行php

问题描述

所以这就是我的桌子的样子:

<div class="container">
    <div class="wrapper">
        <table class="agenda">
            <thead>
                <tr>
                    <th></th>
                    <th>Name</th>
                    <th>Amount</th>
               </tr>
               </thead>
               <tbody>
                   
                   <?php // SELECT ident,COUNT(*) FROM sales GROUP BY ident 
                   
                   foreach($link->query('SELECT ident,COUNT(*) FROM sales GROUP BY ident ASC') as $row) {
                       echo "<tr>";
                       echo "<td>img here</td>";
                       
                       $sql = "SELECT * FROM users WHERE ident='{$row['ident']}'";
                       $resultt = $link->query($sql);
                       if ($resultt->num_rows > 0) {
                           while($roww = $resultt->fetch_assoc()) {
                               
                               echo "<td>" . $roww['fullname'] . "</td>";
                           }
                       }
                       echo "<td>" . $row['COUNT(*)'] . "</td>";
                       echo "</tr>";
                   }
                   ?>
               </tbody>
           </table>
       </div>
   </div>

我将查询行限制为仅 3 行,以显示第一、第二和第三位。在foreach($link->query('SELECT ident,COUNT(*) FROM sales GROUP BY ident ASC') as $row) {. 我怎样才能做一个检查if $row == 1if $row == 2或者if $row == 3

标签: phphtmlmysql

解决方案


在您的 sql 中,您可以使用 LIMIT 关键字,如下所示:

$sql = "SELECT * FROM users WHERE ident='{$row['ident']}' LIMIT 3";

推荐阅读