在系统中,有Events
,EventRosters
,Teams
,TeamRosters
,Members
和Gamertags
。
Events
:视频游戏活动,可以是独奏(1v1)或团队(团队与团队)(示例列:id,类型(独奏/团队),参与者,开始时间,奖品等)。< / p>
EvenRosters
:参与此次比赛的玩家名单,无论是团队活动还是个人活动(如果团队活动,团队!= 0)(示例列:id,event,gamertag,team)
Teams
:由团队数据组成的表格(示例列:id,团队名称,创建日期,公共/私人,图标文件名等)
TeamRosters
:由属于所述团队的成员ID组成的表格(示例列:id,团队,成员)
Members
:由成员数据组成的表格(示例列:id,电子邮件,用户名等)
Gamertags
:由属于成员的gamertags(适用于xbox,playstation等)组成的表(示例列:id,gamertag,member)
对于独奏活动:
Events
:
EventRosters
:
然后是团队活动:
Events
:
EventRosters
:
因此,提取独奏事件非常简单,因为Member_ID
可直接从Event.Challenger
或Event.Contestant
列中获取。但是,如果我们想知道参与团队活动的成员的成员名称,或者我们想要搜索某个成员参与的团队活动,我们会有一些选择。
问题:是否可以在单个查询中获取此数据?
目的:查找两个不同指定成员都参与的团队活动
METHOD 1 : START WITH MEMBER GAMERTAGS
// Fetch team events that two different members both participated in.
$memberID = 3;
$secondMemberID = 5;
$memberGamertags = $pdo->Query('SELECT id FROM member_gamertags WHERE member='.$memberID);
$st = $pdo->Prepare('SELECT event,team FROM event_rosters WHERE team=0 AND gamertag=?');
foreach($memberGamertags as $gt) {
$st->Execute([$gt['id']]);
$rosterFile = $st->Fetch();
$event = $pdo->Query('SELECT id,challenger,contestant FROM events WHERE id='.$rosterFile['event'])->Fetch();
// check if proper team
$otherTeamID = ( $event['challenger'] == $rosterFile['team'] ) ? $event['contestant'] : $event['challenger'];
// now search that team for other member
$otherTeamRoster = $pdo->Query('SELECT * FROM team_rosters WHERE member='.$secondMemberID.' AND team='.$otherTeamID)->Fetch();
if ( $otherTeamRoster ) // found an event they both participated in
$foundEvents[] = $event;
}
//
// REPEAT FOR OTHER MEMBER
//