i'm alittle confused. When i'm sending a query of ORDER BY paramater
desc it should load and present the rows order by the highest number of that paramater to the lower one.
This is my code that im running:
<?php
$p = 1;
$loadusers = mysqli_query($con, "SELECT * FROM `users` ORDER BY `gpower` DESC");
$z = 0;
while ($me = mysqli_fetch_array($loadusers)) {
$z++;
if (($z % 20) == 0) {
$p += 1;
}
if ($me['id'] == $userinfo['id']) {
break;
}
}
if (isset($_GET['sp'])) {
$p = intval($_GET['sp']);
}
$sl = (($p * 20) - 20);
$el = $p * 20;
$loadrank = mysqli_query($con, "SELECT * FROM `users` ORDER BY `gpower` DESC LIMIT $sl,$el");
if (mysqli_num_rows($loadrank) < 1) {
$p = 1;
$sl = (($p * 20) - 20);
$el = $p * 20;
$loadrank = mysqli_query($con, "SELECT * FROM `users` ORDER BY `gpower` DESC LIMIT $sl,$el");
}
$i = $sl;
while ($rs = mysqli_fetch_array($loadrank)) {
$i++;
?>
<tr <?php echo ($rs['id'] == $userinfo['id']) ? "style='background: #7d2222';" : ""?>>
<td><?php echo $i; ?></td>
<td><?php echo secure($rs['name']); ?></td>
<td><?php echo secure($rs['troops']); ?></td>
<td><?php echo clanName($con, $rs['name']); ?></td>
<td><?php echo $rs['gpower']; ?></td>
</tr>
<?php
}
?>
and this is what i'm getting :
Any ideas why does it happend guys?
Your getting a descending ALPHA order
Convert gpower to an int (In SQL Server)
...Order by cast(gpower as int) Desc
Okay, the problem was i've used a Binary type for the gpower
cloumn. i've changed it to float and it worked. When you're using a "ORDER BY paramater
DESC" it will only work if the paramater is numeric type.