根据数据库中列的值中断回显输出
Break echo output based on value from column in database
我在数据库中有 5 tables:
players
(关于玩家的一般信息)
seasons
(table 季节)
clubs
(table关于俱乐部的一般信息)
playerstats
(table 用于玩家统计数据、应用、目标)
clubseason
(table 这就是连接俱乐部和赛季以及俱乐部统计数据)
我想以这种格式回显特定赛季球员的统计数据:
**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} ; ';
}
?>
我在输出中得到这样的信息:
所以基本上我想在这个例子中的每个俱乐部输出后拆分
- Građanski(萨格勒布)然后在 Franz MANTLER(他是这个俱乐部的最后一名球员)之后成为下一行然后是下一个俱乐部
- SAŠK(萨拉热窝)将与 Josip DVORŽAK 球员一起首发
可以做吗?我认为可以,请帮助我提出建议并回答如何操作和中断输出。
first - 您缺少第一个玩家。这是第一个俱乐部的第一个球员的第一行结果,但你只输出俱乐部名称
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/>';
}
我在数据库中有 5 tables:
players
(关于玩家的一般信息)seasons
(table 季节)clubs
(table关于俱乐部的一般信息)playerstats
(table 用于玩家统计数据、应用、目标)clubseason
(table 这就是连接俱乐部和赛季以及俱乐部统计数据)
我想以这种格式回显特定赛季球员的统计数据:
**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} ; ';
}
?>
我在输出中得到这样的信息:
所以基本上我想在这个例子中的每个俱乐部输出后拆分
- Građanski(萨格勒布)然后在 Franz MANTLER(他是这个俱乐部的最后一名球员)之后成为下一行然后是下一个俱乐部
- SAŠK(萨拉热窝)将与 Josip DVORŽAK 球员一起首发
可以做吗?我认为可以,请帮助我提出建议并回答如何操作和中断输出。
first - 您缺少第一个玩家。这是第一个俱乐部的第一个球员的第一行结果,但你只输出俱乐部名称
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/>';
}