Jump to content
php.lv forumi

Vieta tabulā pēc "pts".


nascar

Recommended Posts

Sveiki, lieta tāda ka man iekš DB tabula ir 30 komandas, tālāk es ar šo gribu izvilkt komandas vietu tabulā pēc "pts"

 

Kods:

$team_ranks = mysql_query("SELECT *, pts AS myteamrank, (SELECT COUNT(DISTINCT(pts)) FROM tabula
WHERE pts>myteamrank) AS teamrank FROM tabula WHERE team_saisinajums = '".$_GET['team_saisinajums']."'") or die(mysql_error());
$team_rank = mysql_fetch_array($team_ranks);

 

Un izvadu kā:

<?=$team_rank['teamrank'];?>

 

Kapēc viņš man izvada visām 30 komandām "1" vietu?

Pēc būtības jabūt no 1 > 30, selektojot pēc pts...

 

Ceru ka sapratāt, ko vēlos jums pateikt.

Paldies, Kaspars.

Link to comment
Share on other sites

Es izdariju tā, bet rāda tagad

 

Reference 'myteamrank' not supported (reference to group function)

 

mysql_query("SELECT COUNT(*) AS myteamrank, (SELECT COUNT(DISTINCT(pts)) FROM tabula
WHERE pts>myteamrank) AS teamrank FROM tabula WHERE team_saisinajums = '".$_GET['team_saisinajums']."' GROUP BY pts") or die(mysql_error());

 

Es pieliku tagad grupu klāt, bet tāpatas nekādas izmaiņas... ES uzreiz saku es ar Grupām nēsmu saskārsies...

Link to comment
Share on other sites

Uztaisīju tabulu t2 ar laukiem id,pts. Savadīju pāris vērtība un šis kverijs strādā pareizi:

SELECT *,pts as mypts, (SELECT count(*) as rank FROM t2 WHERE pts>mypts) as myrank FROM t2 WHERE id=300

Edited by codez
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...