Menu ▾ ▴

#24 IP Sorting is not correct

open
nobody
Functions (11)
5
2013-01-08
2007-07-11
web_rene
No

Trying to make some different subnets showed, that the IP sorting is not 100% correct.

Creating an array with the values first and doing a natsort on it, solves the problem in box_CidrMenu.php

e.g.

// After the SQL Queries

$values = array();

# Create array of all IPs.
# This means there mustn't be duplicate IPs!

while($row = mysql_fetch_array($sql)){
$values[$row[NetMenuCidr]]=$row;
}

# Sort the values by Key
$values = natksort($values);

# uncommented:
# while($row = mysql_fetch_array($sql)){
foreach ($values as $key=>$row){

Discussion

  • pascal chartoire

    function natksort($array) {
    // Like ksort but uses natural sort instead
    $keys = array_keys($array);
    natsort($keys);

    foreach ($keys as $k)
    $new_array[$k] = $array[$k];

    return $new_array;
    }

     

Log in to post a comment.