数据库数据中拥有自己的计数器
id | num | text
1 | a | sdfsdf
2 | a | sdfsdf
3 | b | sdfsdf
4 | c | sdfsdf
5 | a | sdfsdf
6 | b | sdfsdf
7 | a | sdfsdf
8 | c | sdfsdf
我在 num = a 和 orderBy ID DESC 处进行查询,我有:
id | num | text
7 | a | sdfsdf
5 | a | sdfsdf
2 | a | sdfsdf
1 | a | sdfsdf
我想为这个自己的计数器添加:
count | id | num | text
4 | 7 | a | sdfsdf
3 | 5 | a | sdfsdf
2 | 2 | a | sdfsdf
1 | 1 | a | sdfsdf
我使用 foreach PHP 获取数据:
foreach ($data as $i => $dat) {
echo $dat->id . $dat->num . $dat->text;
}
我想要一些东西:
foreach ($data as $i => $dat) {
echo $i . $dat->id . $dat->num . $dat->text;
}
但 $i 方向相反
id | num | text
1 | a | sdfsdf
2 | a | sdfsdf
3 | b | sdfsdf
4 | c | sdfsdf
5 | a | sdfsdf
6 | b | sdfsdf
7 | a | sdfsdf
8 | c | sdfsdf
i make query where num = a and orderBy ID DESC and i have:
id | num | text
7 | a | sdfsdf
5 | a | sdfsdf
2 | a | sdfsdf
1 | a | sdfsdf
i would like add for this own counter:
count | id | num | text
4 | 7 | a | sdfsdf
3 | 5 | a | sdfsdf
2 | 2 | a | sdfsdf
1 | 1 | a | sdfsdf
i get data with foreach PHP:
foreach ($data as $i => $dat) {
echo $dat->id . $dat->num . $dat->text;
}
i would like somethings:
foreach ($data as $i => $dat) {
echo $i . $dat->id . $dat->num . $dat->text;
}
but $i in the opposite direction
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你可以这样做:
You can do this:
在 PHP 中:
In PHP:
您知道,您可以在 SQL 查询中解决这个问题。这是针对生产 Redmine 数据库实例 (MySQL) 运行的示例:
You know, you can solve that in your SQL query. This is a sample which a ran against a production Redmine DB instance (MySQL):