php - 检查当前行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 == 1
,if $row == 2
或者if $row == 3
?
解决方案
在您的 sql 中,您可以使用 LIMIT 关键字,如下所示:
$sql = "SELECT * FROM users WHERE ident='{$row['ident']}' LIMIT 3";
推荐阅读
- typescript - Typescript 类:基于泛型类型定义动态属性和类型
- bash - 计算文件的行数并进行比较
- java - 使用 Spring Security 的会话属性
- node.js - 使用 openssl 和 node.js 验证签名
- spring-boot - 无法使用 spring-security-oauth2 和 Tomcat 从 CF 解析 ClientId
- flutter - Facebook无法通过在flutter中安装facebook应用程序登录
- algorithm - 16 位哈希的 FNV_1a 参数是什么?
- android - 开发服务器在运行 react-native 应用程序时返回响应错误代码:500
- hive - sqoop 导出 - 找不到到 postgres 数据库的 parque 文件异常 - 位置不存在
- python - 检查具有相同名称但在两个不同数据帧中的列下的名称是否匹配的最佳代码是什么?在 python 中,使用熊猫?