PHP/SQL-在很多情况下,每4个名称之间打印4个单词多次 [英] php / SQL - print many word 4 times between every 4 names with many conditions
问题描述
i have asked this question before here in this topic please read it carefully sql-print-many-word-between-every-columns-with-many-conditions
但是这个问题和上一个问题之间的区别是,我想在许多俱乐部名称中建立一个集体球员或一群球员,例如:
but the difference between this question and previous one that i want to make a collective players or group of players inside many club names for example :
El Ahly
俱乐部名称有一个12
球员,我想将其分为3
teams
每一个team
有4
球员,我想计算每个俱乐部名称中有多少team
个球员
然后根据它们之间的teams
打印**ANY WORD**
的数量,将它们放入不可变的数字(组)4 8 16 32 64 128 256
中,类似于用select full_name,club_name from players where y_of_birth=2000
过滤数据之后的结果,所需的输出应该是这样的:
El Ahly
club name have a 12
players i want to split it into 3
teams
every team
has 4
players what i want to count how many team
inside every club names
then put them inside immutable numbers (groups) 4 8 16 32 64 128 256
based on the number of teams
print **ANY WORD**
between them something like that after filter data with select full_name,club_name from players where y_of_birth=2000
the desired output should be like that :
已更新:
UPDATED :
+----+------+---------------------+
| full_name | club_name |
+--------------+------------------+
| Ahmed Sayed | El Ahly |
+--------------+------------------+
| Kareem Gaber | El Ahly |
+--------------+------------------+
| Maher Zein | El Ahly |
+--------------+------------------+
| Mohab Saeed | El Ahly |
+----+------+--+------------------+
| ahmed shawky | Petroget |
+--------------+------------------+
| shaker ali | Petroget |
+--------------+------------------+
| omar Saed | Petroget |
+--------------+------------------+
| moataz Gamal | Petroget |
+------+-------+------------------+
| **ANY WORD** | |
+--------------+------------------+
| **ANY WORD** | |
+--------------+------------------+
| **ANY WORD** | |
+--------------+------------------+
| **ANY WORD** | |
+--------------+------------------+
| husein mazen | Cocorico |
+--------------+------------------+
| hassan maged | Cocorico |
+--------------+------------------+
| maged ahmoud | Cocorico |
+--------------+------------------+
| zakareya gad | Cocorico |
+--------------+------------------+
| Kamal saber | El Ahly |
+--------------+------------------+
| gamel kamel | El Ahly |
+--------------+------------------+
| omar galal | El Ahly |
+--------------+------------------+
| Kamal saber | El Ahly |
+--------------+------------------+
| **ANY WORD** | |
+--------------+------------------+
| **ANY WORD** | |
+--------------+------------------+
| **ANY WORD** | |
+--------------+------------------+
| **ANY WORD** | |
+--------------+------------------+
| khaled zein | Petroget |
+--------------+------------------+
| shady sameer | Petroget |
+--------------+------------------+
| wahed mahmoud| Petroget |
+--------------+------------------+
| samy shahen | Petroget |
+----+------+--+------------------+
| Mohamed gad | El Ahly |
+----+------+--+------------------+
| ehab zeyad | El Ahly |
+----+---------+------------------+
| moaz maged | El Ahly |
+--------------+------------------+
| mazen mahmod | El Ahly |
+--------------+------------------+
在此示例中,
是2 groups of
**ANY WORD**
,因为它是6
group
并将它们放入在4
或8
或16
或32
中找到的8
不可变组中.或64
或128
或256
数字...并且在两个**ANY WORD**
之间没有相邻,或者在club_name
in this example there are 2 groups of
**ANY WORD**
because its a 6
group
and put them inside 8
immutable group which found in 4
or 8
or 16
or 32
or 64
or 128
or 256
numbers ... and no adjacent between 2 **ANY WORD**
or two adjacent between club_name
示例:
4个玩家为一个玩家
如果select full_name,club_name from players where y_of_birth=2000
之后的结果是12
个玩家,则表示12 players
= 3 groups
,因为每个组都有4
个玩家下一步打印**ANY WORD**
4次(注意:**ANY WORD**
是以下一项)这些组)在3组之间,因此输出将是这样的:
if the result after select full_name,club_name from players where y_of_birth=2000
is 12
players it mean 12 players
= 3 groups
because every group have 4
players next step print **ANY WORD**
4 times (note: **ANY WORD**
is a one of these groups) between 3 groups so the output will be like that :
+----+------+---------------------+
| full_name | club_name |
+--------------+------------------+
| Ahmed Sayed | El Ahly |
+--------------+------------------+
| Kareem Gaber | El Ahly |
+--------------+------------------+
| Maher Zein | El Ahly |
+--------------+------------------+
| Mohab Saeed | El Ahly |
+----+------+--+------------------+
| ahmed shawky | Petroget |
+--------------+------------------+
| shaker ali | Petroget |
+--------------+------------------+
| omar Saed | Petroget |
+--------------+------------------+
| moataz Gamal | Petroget |
+------+-------+------------------+
| **ANY WORD** | |
+--------------+------------------+
| **ANY WORD** | |
+--------------+------------------+
| **ANY WORD** | |
+--------------+------------------+
| **ANY WORD** | |
+--------------+------------------+
| Kamal saber | El Ahly |
+--------------+------------------+
| gamel kamel | El Ahly |
+--------------+------------------+
| omar galal | El Ahly |
+--------------+------------------+
| Kamal saber | El Ahly |
+--------------+------------------+
结论:
4 8 16 32 64 128 256
是不可变的组
group 4
应该将**ANY WORD**
个玩家填充到16
个玩家中,并且彼此之间没有任何类似的内容:
group 4
should fill of 16
players with **ANY WORD**
with no adjacent between them something like that :
+----+------+---------------------+
| full_name | club_name |
+--------------+------------------+
| Ahmed Sayed | El Ahly |
+--------------+------------------+
| Kareem Gaber | El Ahly |
+--------------+------------------+
| Maher Zein | El Ahly |
+--------------+------------------+
| Mohab Saeed | El Ahly |
+----+------+--+------------------+
| ahmed shawky | Petroget |
+--------------+------------------+
| shaker ali | Petroget |
+--------------+------------------+
| omar Saed | Petroget |
+--------------+------------------+
| moataz Gamal | Petroget |
+------+-------+------------------+
| **ANY WORD** | |
+--------------+------------------+
| **ANY WORD** | |
+--------------+------------------+
| **ANY WORD** | |
+--------------+------------------+
| **ANY WORD** | |
+--------------+------------------+
| Kamal saber | El Ahly |
+--------------+------------------+
| gamel kamel | El Ahly |
+--------------+------------------+
| omar galal | El Ahly |
+--------------+------------------+
| Kamal saber | El Ahly |
+--------------+------------------+
group 8
应该用**ANY WORD**
填充32
个玩家,并且彼此之间不存在类似的东西:
group 8
should fill of 32
players with **ANY WORD**
with no adjacent between them something like that :
+----+------+---------------------+
| full_name | club_name |
+--------------+------------------+
| Ahmed Sayed | El Ahly |
+--------------+------------------+
| Kareem Gaber | El Ahly |
+--------------+------------------+
| Maher Zein | El Ahly |
+--------------+------------------+
| Mohab Saeed | El Ahly |
+----+------+--+------------------+
| ahmed shawky | Petroget |
+--------------+------------------+
| shaker ali | Petroget |
+--------------+------------------+
| omar Saed | Petroget |
+--------------+------------------+
| moataz Gamal | Petroget |
+------+-------+------------------+
| **ANY WORD** | |
+--------------+------------------+
| **ANY WORD** | |
+--------------+------------------+
| **ANY WORD** | |
+--------------+------------------+
| **ANY WORD** | |
+--------------+------------------+
| husein mazen | Cocorico |
+--------------+------------------+
| hassan maged | Cocorico |
+--------------+------------------+
| maged ahmoud | Cocorico |
+--------------+------------------+
| zakareya gad | Cocorico |
+--------------+------------------+
| Kamal saber | El Ahly |
+--------------+------------------+
| gamel kamel | El Ahly |
+--------------+------------------+
| omar galal | El Ahly |
+--------------+------------------+
| Kamal saber | El Ahly |
+--------------+------------------+
| **ANY WORD** | |
+--------------+------------------+
| **ANY WORD** | |
+--------------+------------------+
| **ANY WORD** | |
+--------------+------------------+
| **ANY WORD** | |
+--------------+------------------+
| khaled zein | Petroget |
+--------------+------------------+
| shady sameer | Petroget |
+--------------+------------------+
| wahed mahmoud| Petroget |
+--------------+------------------+
| samy shahen | Petroget |
+----+------+--+------------------+
| Mohamed gad | El Ahly |
+----+------+--+------------------+
| ehab zeyad | El Ahly |
+----+---------+------------------+
| moaz maged | El Ahly |
+--------------+------------------+
| mazen mahmod | El Ahly |
+--------------+------------------+
等等
group 16
group 32
group 64
group 128
group 256
已
EDITED:
我从 Gordon Linoff
select p.*
from (select p.*,
(@rn := if(@c = club_name, @rn + 1,
if(@c := club_name, 1, 1)
)
) as seqnum
from players p cross join
(select @c := '', @rn := 0) params
order by club_name
) p
order by floor((seqnum - 1) / 4), club_name
结合过滤后的数据:
select p.*
from (select p.full_name,club_name,
(@rn := if(@c = club_name, @rn + 1,
if(@c := club_name, 1, 1)
)
) as seqnum
from players p cross join
(select @c := '', @rn := 0) params WHERE `y_of_birth` LIKE N'%2000%'
order by club_name
) p
order by floor((seqnum - 1) / 4), club_name
输出类似的内容:
+----+------+---------------------+
| full_name | club_name |
+--------------+------------------+
| Ahmed Sayed | El Ahly |
+--------------+------------------+
| Kareem Gaber | El Ahly |
+--------------+------------------+
| Maher Zein | El Ahly |
+--------------+------------------+
| Mohab Saeed | El Ahly |
+----+------+--+------------------+
| kamal mado | Cocorico |
+--------------+------------------+
| hossam magdy | Cocorico |
+--------------+------------------+
| sayed ammar | Cocorico |
+--------------+------------------+
| karem gad | Cocorico |
+--------------+------------------+
| Mohamed gad | El Ahly |
+----+------+--+------------------+
| ehab zeyad | El Ahly |
+----+---------+------------------+
| moaz maged | El Ahly |
+--------------+------------------+
| mazen mahmod | El Ahly |
+--------------+------------------+
| shaker ali | Petroget |
+--------------+------------------+
| omar Saed | Petroget |
+--------------+------------------+
| moataz Gamal | Petroget |
+--------------+------------------+
| gamael zayed | Petroget |
+--------------+------------------+
| husein mazen | Cocorico |
+--------------+------------------+
| mazen kamal | Cocorico |
+--------------+------------------+
| maged ahmoud | Cocorico |
+--------------+------------------+
| mesho kareem | Cocorico |
+--------------+------------------+
| mano mazen | Petroget |
+--------------+------------------+
| shady srour | Petroget |
+--------------+------------------+
| mamdouh gamal| Petroget |
+--------------+------------------+
| khaled zein | Petroget |
+--------------+------------------+
| husein mazen | Cocorico |
+--------------+------------------+
| hassan maged | Cocorico |
+--------------+------------------+
| maged ahmoud | Cocorico |
+--------------+------------------+
| zakareya gad | Cocorico |
+--------------+------------------+
| shady sameer | Petroget |
+--------------+------------------+
| wahed mahmoud| Petroget |
+--------------+------------------+
| samy shahen | Petroget |
+----+------+--+------------------+
| abdo samy | Petroget |
+----+------+--+------------------+
任何帮助将不胜感激!
推荐答案
我阅读了您之前的文章和这篇文章.如果我有这个主意,最基本的是您有团队,有球员,并且想要按特定的标准化分组(可以说)显示数据.
I read your previous post and this one. If I get the idea, the basic thing is you have teams and you have players and you want to display data in certain standardized groupings (so-to-speak).
好吧,您一直在比较一个不变的数据,那就是团队的规模.
Well, there is a constant datum that you are always comparing to which is the size of the team.
我要做的是创建一个子查询,该子查询将团队与球员人数进行分组,并以某种方式使用该子查询,如下所示:
What I would do is make a subquery that groups the team with a count of the players and use this in some fashion as follows:
select t.*
, x.total_players
-- , row_number() over(order by t.team_name) row_id
from team_table t
join (
select team_id
, count(1) total_playerss
from team_table
group by team_id
) x on x.team_id = t.team_id
order by t.team_name
在PHP中回显结果集时,您可以构建一些函数,例如:
When echo'ing out the result set in PHP, you can build some function such as:
<?php
function add_some_word($playerCount) {
if ($playerCount >4 && $playerCount <= 8) {
echo '*** SOME WORD***';
echo '*** SOME WORD***';
echo '*** SOME WORD***';
}
else if ($playerCount >4 && $playerCount <= 8) {
echo '*** SOME WORD***';
echo '*** SOME WORD***';
}
// etc.
}
?>
使用结果集中的row_id
,您可以查看团队的开始和结束时间.
Using the row_id
from the result set, you can see when a team starts and ends.
因此,当它分散行时,可能类似于:"
So when it is spitting out the rows it could be something like:"
<?php
$currentTeamName = "";
while ($row = pg_fetch_array($result,null,PGSQL_ASSOC)) {
// echo data you would normally send out
if ($currentTeamName != $row['team_name']) {
add_some_word($row['total_players']);
}
}
?>
希望您的问题正确.我正在快速解决这个问题,但我认为这会有所帮助!
I hope I got your question right. I am dashing this off fast but I thought it would help!
这篇关于PHP/SQL-在很多情况下,每4个名称之间打印4个单词多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!