Jump to content

Sorting Arrays


McGod
 Share

Recommended Posts

Ok I got an date array and it needs to be organized. I grab the dates (20070118193735|YEARMONDAYHRMINSEC) then I need to organize them them highest at the top, but i need to have the multi dims so I can figure out which post is where. Ill explain a bit more.

$sArray[1][0] = "20070117125235"

$sArray[1][1] = "1"

$sArray[2][0] = "20070118193735"

$sArray[2][1] = "2"

$sArray[1][0] = "20070118193735"

$sArray[1][1] = "2"

$sArray[2][0] = "20070117125235"

$sArray[2][1] = "1"

So, Post "1" has been posted in last yesterday and Post "2" was today. That would be what it looks like AFTER Sorting.

This is a huge speedbump in my forums and i just cant seem to figure it out!!! :)

Link to comment
Share on other sites

Ok I got an date array and it needs to be organized. I grab the dates (20070118193735|YEARMONDAYHRMINSEC) then I need to organize them them highest at the top, but i need to have the multi dims so I can figure out which post is where. Ill explain a bit more.

So, Post "1" has been posted in last yesterday and Post "2" was today. That would be what it looks like AFTER Sorting.

This is a huge speedbump in my forums and i just cant seem to figure it out!!! :)

#include <Array.au3>

_ArraySort()
Link to comment
Share on other sites

I've been trying to work with _ArraySort

Link to comment
Share on other sites

May I suggest a func similar to this:

$sArray[2][0] = "20070117125235"
$sArray[1][0] = "20070118193735"
$trimyear1 = StringTrimRight($sArray[1][0], 10)
$trimyear2 = StringTrimRight($sArray[2][0], 10)
If $trimyear1 < $trimyear2 Then
   ;do whatever
Else
   If $trimyear1 = $trimyear2 Then
      $trimmonth1 = StringTrimRight($sArray[1], 8)
      $trimmonth2 = StringTrimRight($sArray[2], 8)
      $trimmonth1 = StringTrimLeft($trimmonth1, 4)
      $trimmonth2 = StringTrimLeft($trimmonth2, 4)
      If $trimmonth1 < $trimmonth2 Then
         ;and so on

Just an idea, I guess. it basically checks if $x's year is bigger than $y's, if the year isn't bigger and if it's equal, it checks the month.. and so on..

Hopefully I make sense,

Kurt

EDIT: minor fix in script

Edited by _Kurt

Awaiting Diablo III..

Link to comment
Share on other sites

It does but there can be 50 variables. Its for post by date for my Au3Forums.

K what I need it to do is _ArraySort my $sArray[1][0] And move the [1] where the correlating [0] is so say it

$sArray[1][0] = "9"

$sArray[1][1] = "4"

$sArray[2][0] = "3"

$sArray[2][1] = "22"

$sArray[3][0] = "1"

$sArray[3][1] = "5"

So I want to arrange [1][0], [2][0] and [3][0] by there number so it would be like 1, 3, 9 And have the the [1][1] [2][1] [3][1] Move accordingly. So it would look like.

$sArray[1][0] = "1"

$sArray[1][1] = "5"

$sArray[2][0] = "3"

$sArray[2][1] = "22"

$sArray[2][0] = "9"

$sArray[4][0] = "4"

Note the 4, 22, 5 moved to where they are suppose to be.

Edited by Chip
Link to comment
Share on other sites

Woops, never thought of that. Hmm, that's a toughy, perhaps arranging dates/times in a different format rather than YEARMONDAYHRMINSEC ? Or if you can't find anything, perhaps creating a function based off the example above considering that StringTrim's run relatively fast, something like Sort($sArray1,$sArray2). Or maybe writting in some sort of log, saying that $sArray will always be 2nd in the webpage, etc. Sorry buddy, can't really help you out, don't know how your WebForum thing works, and evidentely I am of no use.

:)

Kurt

Awaiting Diablo III..

Link to comment
Share on other sites

hmm, basically what I need is a _ArraySort that shuffles the second dim.

Link to comment
Share on other sites

OMG IM SO HAPPY, I added 4 words to the end of my sql query and it SORTS IT FOR ME OMG IM SO HAPPY!!!!

ORDER BY LastPostDate DESC

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...