Jump to content

order by or limit by specific colum


JJohnsenDK

Recommended Posts

Hey

I was wondering if its possible to order by or limit by a specific colum. I have a football table/league table with 12 teams and one of those teams are "my team". I want to make a "mini" league table where i only show 6 of the teams but "my team" has to be in the middle, so it doesnt mather if "my team" is in the 1 place or in the 10 place, it will allways apear as one of the 6 teams. Like this

4. "My team"
5. Viborg
6. Aab
7. OB
8. FCK
9. Brøndby

OR

7. OB
8. FCM
9. FCN
10. FCK
11. Vejle
12. "My Team"

Here is the code im using now. It only shows top six of the table no mather where "my team" is placed in the table:


[code]
<table>
<tr>
<td width='100'><b>Klub</b></td>
<td width='30' align='center'><b>K</b></title></td>
<td width='30' align='center'><b>P</b></td>
</tr>
<tr>
<td colspan='3'><img src='images/black.jpg' width='100%' height='1'></td>
</tr>
<?php
$sql2 = "SELECT league.team_id, league.rounds, league.points, league.season, team.name
FROM league
INNER JOIN team ON league.team_id = team.team_id
WHERE league.season = '2006'
ORDER BY league.points DESC
LIMIT 6";
$result2 = mysql_query($sql2);
while($row2 = mysql_fetch_array($result2)){
?>
<tr>
<td><?=$row2['name']; ?></td>
<td align='center'><?=$row2['rounds']; ?></td>
<td align='center'><?=$row2['points']; ?></td>
</tr>
<tr>
<td colspan='3'><img src='images/black.jpg' width='100%' height='1'></td>
</tr>
<?php
}
?>
<tr>
<td colspan='3' align='right'><a href='sasliga.php'>mere></a></td>
</tr>
</table>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/35385-order-by-or-limit-by-specific-colum/
Share on other sites

you could [color=red]ORDER BY league.id='somevalue',league.points DESC[/color] but your team would always be first on the list -- the remaining teams would be sorted in order of points. "somevalue" would be a value representing your team.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.