Pozz,
Imam ovu skriptu koja mi prikazuje timove i broj bodova
<table>
<tr>
<th style="width:5%;">#</th>
<th style="width:10%;">Points</th>
<th style="width:64%;">Name</th>
<th style="width:3%;">W</th>
<th style="width:3%;">D</th>
<th style="width:3%;">L</th>
<th style="width:15%;"></th>
</tr>
<?php
foreach ($TEAM as $key)
{
echo '<tr>
<td>tu treba da mi pise 1, 2, 3, 4....</td>
<td>'.$key['team_points'].'</td>
<td><a href="team.php?id='.$key['team_id'].'" title="'.$key['team_name'].'">'.$key['team_name'].'</a></td>
<td>'.$key['team_wins'].'</td>
<td>'.$key['team_draws'].'</td>
<td>'.$key['team_lose'].'</td>
<td><a href="ladders.php?game='.$game.'&id='.$id.'&tid='.$key['team_id'].'&action=challenge" title="Challenge">Challenge</a></td>
</tr>';
}
?>
</table>
Kako da napravim da mi prikazuje od tima koji ima najvise bodova prema manjem i da mi izbaci 1,2,3,4,5,6,7,8… znaci ako prvi ima najvise bodova 1, drugi 2 itd
evo i slika http://prntscr.com/3i7lbt
<?php
$rb = 1;
foreach ($TEAM as $key)
{
tvoj kod
$rb++;
}
?>
nadam se da sam pomogao. tamo gdje ti piše “tu treba da mi piše” stavi da ti ispisuje $rb sa točkom
Jesi radi :D, hvala ti puno
Evo ti kako bi sortiranje izgledalo:
<table>
<tr>
<th style="width:5%;">#</th>
<th style="width:10%;">Points</th>
<th style="width:64%;">Name</th>
<th style="width:3%;">W</th>
<th style="width:3%;">D</th>
<th style="width:3%;">L</th>
<th style="width:15%;"></th>
</tr>
<?php
$poredak = 1;
$sortArray = array();
foreach( $TEAM as $key ) {
foreach( $key as $index => $value ) {
if( ! isset( $sortArray[ $index ] ) ) {
$sortArray[ $index ] = array();
}
$sortArray[ $index ][] = $value;
}
}
array_multisort( $sortArray['team_points'], SORT_DESC, $TEAM );
foreach ( $TEAM as $key )
{
echo '<tr>
<td>'.$poredak.'</td>
<td>'.$key['team_points'].'</td>
<td><a href="team.php?id='.$key['team_id'].'" title="'.$key['team_name'].'">'.$key['team_name'].'</a></td>
<td>'.$key['team_wins'].'</td>
<td>'.$key['team_draws'].'</td>
<td>'.$key['team_lose'].'</td>
<td><a href="ladders.php?game='.$game.'&id='.$id.'&tid='.$key['team_id'].'&action=challenge" title="Challenge">Challenge</a></td>
</tr>';
$poredak++;
}
?>
</table>
Pozz da ne otvaram novu temu a problem isti samo s malo drugacijim kodom
<table width="100%" class="ladder-table2">
<tr>
<th style="width:7%;">#</th>
<th style="width:70%;">Team</th>
<th style="width:6%;">W</th>
<th style="width:6%;">D</th>
<th style="width:6%;">L</th>
<th style="width:12%;">Points</th>
</tr>
<?php
$poredak = 1;
foreach ($get_team_id as $gti)
{
$tid = $gti['team_id']; // team id
// get teams points
$get_team_points = $teams->ladders_get_team_points($id, $tid);
// get team name
$get_team_name = $teams->ladders_get_team_name($tid);
foreach ($get_team_points as $gtp)
{
foreach ($get_team_name as $gtn)
{
echo '<tr>';
echo '
<td>'.$poredak.'</td>
<td><a href="" title="'.$gtn['team_name'].'">'.$gtn['team_name'].'</td>
<td>'.$gtp['team_wins'].'</td>
<td>'.$gtp['team_draws'].'</td>
<td>'.$gtp['team_loses'].'</td>
<td>'.$gtp['team_points'].'</td>
';
echo '</tr>';
}
}
$poredak++;
}
?>
</table>
Sad mi lista 1, 2, 3, 4 ali ne po bodovima evo i slika http://prntscr.com/3mfgix
Da napomenem samo prvo foreach uzima samo ID, drugi foreach BROJ BODOVA, a treci foreach IME TIMA
probo sam i ovako
foreach ($get_team_id as $gti)
{
$tid = $gti['team_id']; // team id
// get teams points
$get_team_points = $teams->ladders_get_team_points($id, $tid);
// get team name
$get_team_name = $teams->ladders_get_team_name($tid);
$poredak = 1;
foreach ($get_team_points as $gtp)
{
foreach ($get_team_name as $gtn)
{
echo '<tr>';
echo '
<td>'.$poredak.'</td>
<td><a href="" title="'.$gtn['team_name'].'">'.$gtn['team_name'].'</td>
<td>'.$gtp['team_wins'].'</td>
<td>'.$gtp['team_draws'].'</td>
<td>'.$gtp['team_loses'].'</td>
<td>'.$gtp['team_points'].'</td>
';
echo '</tr>';
}
$poredak++;
}
}
I s time mi stavi sve 1, 1, 1, 1, 1
probaj $poredak = 1; staviti prije prvog foreach
Rjesio sam bio problem u queriju napravio sam novi
// list teams in ladders sort by team_points from highest to lowest
public function ladders_list_teams($id)
{
$query = $this->db->prepare("SELECT a.team_id, a.ladder_id, a.team_points, a.team_wins, a.team_draws, a.team_loses, b.team_name FROM team_points a LEFT JOIN team b ON b.id = a.team_id WHERE a.ladder_id = ? ORDER BY team_points ASC");
$query->bindValue(1, $id);
$query->execute();
return $query->fetchAll();
}
I ovako radi sad
<?php
// list all teams, team points, wins, draw, losses in selected ladder
$lst = $teams->ladders_list_teams($id);
$position = 1;
foreach ($lst as $key)
{
echo '<tr>';
echo '
<td>'.$position.'</td>
<td><a href="index.php?page=teams&teamID='.$key['team_id'].'" title="'.$key['team_name'].'">'.$key['team_name'].'</td>
<td>'.$key['team_wins'].'</td>
<td>'.$key['team_draws'].'</td>
<td>'.$key['team_loses'].'</td>
<td>'.$key['team_points'].'</td>
';
echo '</tr>';
$position++;
}
?>