How to make auto index sort files with numbers like 1-1000

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to make auto index sort files with numbers like 1-1000

    Hi,

    Its been a while since I posted and visited this site, a lot have changed. Anyhow I have encountered a problem and I was like searching the web but can't find the right words to search.

    I have encountered a problem in auto index scripts when sorting A-Z and if the files have numbers like example Naruto episode 1 - 1000. I kinda sorts like FF:
    Naruto episode 1
    Naruto episode 10 up to 20
    Naruto Episode 2
    Naruto episode 21-30
    Naruto 3

    Something like that, is there a way to make it sort in right order? I dunno if I am making sense. T_T

    #2
    Hi.

    Just rename Naruto episode 1 to Naruto episode 01, 2 to 02 and so on...
    <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

    Comment


      #3
      Here is a sort function i created for you :P
      PHP Code:
      <?
      $vids = array('N 1','N 10','N 11','N 12','N 13','N 14','N 15','N 16','N 17','N 18','N 19','N 2','N 20','N 21','N 22','N 23','N 24','N 25','N 26','N 27','N 28','N 29','N 3','N 30','N 31', 'N 4', 'N 5', 'N 6', 'N 7', 'N 8', 'N 9');

      function sortedBySE($a, $b)
      {
          $a = explode(' ', $a);
          $b = explode(' ', $b);
          $c = (count($a) > count($b)) ? count($a) : count($b);
          foreach(range(0, $c) as $i)
          {
              if($a[$i] < $b[$i])
              {
                  return -1;
              }
              else if($a[$i] > $b[$i])
              {
                  return 1;
              }
          }
          return -1;
      }

      usort($vids, "sortedBySE");
      print_r($vids);
      ?>
      It may need slight work to make it work better for you - but at least you have something to work with
      Last edited by something else; 10.11.14, 19:35.

      Comment


        #4
        I am unable to understand the function that you have provided ...
        You populate an array $vids but then in the function you carry out check match and sort on $a , $b ..
        also when you implement usort function is it not supposed to be
        Code:
        [COLOR=#000000][COLOR=#0000BB]usort[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$vids[/COLOR][COLOR=#007700], [/COLOR][COLOR=#DD0000]"sortedBySE()"[/COLOR][COLOR=#007700]);[/COLOR][/COLOR]
        This function provided by you is confusing!
        tinyurl.com/earnbymobile
        Easy earning for Indians
        ---------------------
        Alternative mobile advertising network .. Minimum 100 USD pay / NET15 pay cycle, Good Brand, Best targeting for Android
        goo.gl/6vub3

        Comment


          #5
          Nope it is meant to be like i have wrote it

          Its because no variables can be included inside that function (due to usort passing 2 of the array items at a time to the user created function (a,b) and comparing the 2 and then called as many times as it is needed in an algorithm until the whole array is sorted.

          If you do need to pass extra variables to the user function then rather than use global variables you can use use

          and yes confusing >.< and i am probably not making it easier to understand with this post lol
          Last edited by something else; 14.11.14, 13:39.

          Comment


            #6
            Originally posted by something else View Post
            Here is a sort function i created for you :P
            PHP Code:
            <?
            $vids = array('N 1','N 10','N 11','N 12','N 13','N 14','N 15','N 16','N 17','N 18','N 19','N 2','N 20','N 21','N 22','N 23','N 24','N 25','N 26','N 27','N 28','N 29','N 3','N 30','N 31', 'N 4', 'N 5', 'N 6', 'N 7', 'N 8', 'N 9');

            function sortedBySE($a, $b)
            {
            $a = explode(' ', $a);
            $b = explode(' ', $b);
            $c = (count($a) > count($b)) ? count($a) : count($b);
            foreach(range(0, $c) as $i)
            {
            if($a[$i] < $b[$i])
            {
            return -1;
            }
            else if($a[$i] > $b[$i])
            {
            return 1;
            }
            }
            return -1;
            }

            usort($vids, "sortedBySE");
            print_r($vids);
            ?>
            It may need slight work to make it work better for you - but at least you have something to work with

            Im looking at this trying to work out why i put range( ) in this >.<

            It could also do with some alphabetical sorting also

            Comment

            Working...
            X