-5

我有一张桌子,里面有一群有一定积分的用户。我想将用户从最高点排列到最低点。但是 ORDER BY PTS DESC 不起作用。

                    <tr>
                        <th id="users_th1"><img src="<?php echo mysql_result($r_TEAMS, $i, 'LOGO'); ?>"/> <p><?php echo mysql_result($r_TEAMS, $i, 'NAME'); ?></p></th>
                        <th id="users_th2">Points Value</th>
                    </tr>
                    <?php 
                    $q_users = 'Select * from POINTS LEFT JOIN USERS on USERS.UID = POINTS.UID where TID = '.mysql_result($r_TEAMS, $i, 'TID');
                    $r_users = mysql_query($q_users, $connection) or die(mysql_error());
                    $n_users = mysql_num_rows($r_users);

                        for($k = 0; $k <$n_users; $k++){    
                    ?>



                    <tr>
                        <td class="person"><?php echo mysql_result($r_users, $k, 'NAME'); ?></td>
                        <td><?php echo mysql_result($r_users, $k, 'POINTS.PTS'); ?></td>
                    </tr>

                    <?php
                        }
                    }
4

2 回答 2

1

这只是猜测,但我看到你正在做一个JOINbetween tableUSER和 table POINTS。也许您PTS两个表中都调用了一个字段,因此如果您想按该字段对结果进行排序,您应该指出您所指的那个表属于哪个表。

所以,这样做,

$q_users = "
    SELECT *
    FROM POINTS
    LEFT JOIN USERS
    ON USERS.UID = POINTS.UID
    WHERE <table name>.TID = " . mysql_result($r_TEAMS, $i, 'TID') . "
    ORDER BY <table name>.PTS DESC";
于 2013-08-23T16:01:30.447 回答
0

你试过了吗:

$q_users = 'Select * from POINTS LEFT JOIN USERS on USERS.UID = POINTS.UID where TID = '.mysql_result($r_TEAMS, $i, 'TID').' ORDER BY PTS DESC;';

如果它不排序或不查询,你也可以写。

于 2013-08-23T15:57:15.580 回答