根据数据库中列的值中断回显输出

时间:2015-05-15 14:52:05

标签: php mysql joomla mysqli

我在数据库中有5个表:

  • players(有关玩家的一般信息)
  • seasons(季节表)
  • clubs(关于俱乐部的一般信息表)
  • playerstats(球员统计,应用,目标表)
  • clubseason(表连接俱乐部和季节以及俱乐部统计数据)

我希望以这种格式回应玩家的统计数据:

**1. CLUB 1** 
Players from that club (club 1) in that season (apps/goals) etc
**2. CLUB 2** 
Players from club 2 with stats
etc 
sorted based on club positions in that season

我开发了php代码

<?php
include('connect-mysql.php');
$sqlchc = "SELECT jos_igraciDB_season.idSeason, jos_igraciDB_season.seasonURL FROM jos_igraciDB_season ORDER BY `jos_igraciDB_season`.`idSeason`";
$res = mysql_query($sqlchc);
$article_id = JFactory::getApplication()->input->get('id');
while($rowt=mysql_fetch_assoc($res)){
  if ($article_id == $rowt['seasonURL']) {
    $urlID = $rowt['idSeason']; 
  }
}
$sqlcom = "SELECT jos_clubseason.clubposition, jos_players.firstName, jos_players.lastName, jos_players.position, jos_players.playerpic, jos_playerstats.idClub, jos_playerstats.idSeason, jos_igraciDB_club.name, jos_playerstats.apps, jos_playerstats.goals, jos_players.idPlayer
 FROM `jos_playerstats` JOIN `jos_igraciDB_club` ON `jos_playerstats`.`idClub` = `jos_igraciDB_club`.`idClub` JOIN `jos_igraciDB_season` ON `jos_playerstats`.`idSeason` = `jos_igraciDB_season`.`idSeason` JOIN `jos_players` ON `jos_playerstats`.`idPlayer` = `jos_players`.`idPlayer` JOIN `jos_clubseason` ON `jos_playerstats`.`idClub` = `jos_clubseason`.`idClub` WHERE `jos_playerstats`.`idSeason` = '".$urlID."' AND `jos_clubseason`.`idSeason` = '".$urlID."' ORDER BY clubposition, position";
$result = mysql_query($sqlcom);
$row2=mysql_fetch_assoc($result);
echo '<strong>'.$row2['clubposition'].'. '.$row2['name'].'</strong>';   echo '<p>';
while($row=mysql_fetch_assoc($result)) {
   echo '{modal igraci/article/'.$row['idPlayer'].'|width=500|height=400|title='.mb_strtoupper($row['lastName'], 'UTF-8').' '.mb_strtoupper($row['firstName'], 'UTF-8').'}'.$row['firstName'].' '.mb_strtoupper($row['lastName'], 'UTF-8').' ('.$row['apps'].'/'.$row['goals'].'){/modal} ; '; 
} 
?>

我在输出中得到这样的东西: echo output for stats

所以基本上我想在这个例子中的每个俱乐部输出后分开

  1. Građanski(萨格勒布)然后在Franz MANTLER(这个俱乐部的最后一名球员)之后成为下一线,然后是下一个俱乐部
  2. SAŠK(萨拉热窝)将从JosipDVORŽAK播放器开始
  3. 可以吗?我认为它可以,请帮助我提出建议和解答该怎么做并打破输出。

1 个答案:

答案 0 :(得分:1)

首先 - 你错过了第一个玩家。这是第一个俱乐部中的第一个球员的第一线结果,但是您只输出俱乐部名称

echo '<strong>'.$row2['clubposition'].'. '.$row2['name'].'</strong>'; 
实现你想要的最简单方法是存储俱乐部位置并进行比较。

$currentClub = 0;
while($row=mysql_fetch_assoc($result)) {
       if ($row2['clubposition'] != $currentClub) {
            $currentClub = $row2['clubposition'];
            echo '<strong>'.$row2['clubposition'].'. '.$row2['name'].'</strong>';   echo '<p>';
       }
       echo '{modal igraci/article/'.$row['idPlayer'].'|width=500|height=400|title='.mb_strtoupper($row['lastName'], 'UTF-8').' '.mb_strtoupper($row['firstName'], 'UTF-8').'}'.$row['firstName'].' '.mb_strtoupper($row['lastName'], 'UTF-8').' ('.$row['apps'].'/'.$row['goals'].'){/modal} ; <br/>'; 
    }