Есть таблица, из базы берется данные, по последнему столбцу (Сумма) пытаюсь сортировку сделать (сверху больше), через ORDER пытался, не выходит.
<form style="margin: 0px;" method="post" action="<?php echo $_SERVER['PHP_SELF']; echo "?offset=".$_REQUEST['offset'].$q_string; ?>" name="form1" >
<input type="hidden" name="offset" value="<?php echo $_REQUEST['offset'];?>">
<?php
if ($count > $records_per_page) {
// calculate number of pages & current page
echo "<center>";
$label["navigation_page"] = str_replace ("%CUR_PAGE%", $cur_page, $label["navigation_page"]);
$label["navigation_page"] = str_replace ("%PAGES%", $pages, $label["navigation_page"]);
//echo "<span > ".$label["navigation_page"]."</span> ";
$nav = nav_pages_struct( $q_string, $count, $records_per_page );
$LINKS = 10;
render_nav_pages($nav, $LINKS, $q_string);
echo "</center>";
}
?>
<table id="ratingTable" width="100%" cellSpacing="1" cellPadding="3" align="center" bgColor="#d9d9d9" border="0">
<thead>
<tr>
<th>Name</th>
<th>CompName</th>
<th>Pixels</th>
</tr>
</thead>
<?php
$i=0;
while (($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) && ($i<$records_per_page)) {
$i++;
$sql = "SELECT SUM(quantity) as Pixels FROM orders where (status='completed') AND user_id=".intval($row['ID']);
$result2 = mysqli_query($GLOBALS['connection'], $sql) or die (mysqli_error($GLOBALS['connection']).$sql);
$order_row = mysqli_fetch_array($result2);
$sql = "SELECT * FROM orders where user_id='".intval($row['ID'])."' AND status <> 'new' ";
$result3 = mysqli_query($GLOBALS['connection'], $sql) or die (mysqli_error($GLOBALS['connection']));
//$row = mysqli_fetch_array($result);
?>
<tbody>
<tr class="item">
<td><?php echo $row['FirstName'] . " / " . $row['LastName'];?></td>
<td><?php echo $row['CompName'];?></td>
<td><?php echo ($order_row['Pixels'] * 0.15). " $ ";?></td>
</tr>
</tbody>
<?php
}
?>
</table>
</form>