PHP/MYSQL - "ORDER BY" Doesn't work -
i have table bunch of users have amount of points. arrange users highest points first lowest. order pts desc doesn't work.
<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 * points left join users on users.uid = points.uid 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 } }
this guesswork, see you're doing join
between table user
, table points
. perhaps have field called pts
in both tables, if want order results field should indicate table 1 you're referring belongs.
so, way,
$q_users = " select * points left join users on users.uid = points.uid <table name>.tid = " . mysql_result($r_teams, $i, 'tid') . " order <table name>.pts desc";
Comments
Post a Comment