Ask a Question related to PHP Development, Design and Development.
-
Dan Joseph #1
Array Sorting, 2 items...
Hi,
Trying to accomplish:
I want to sort my array by two columns. The array is setup:
Array
(
[0] => Array
(
[0] => CHECKING
[ba_type] => CHECKING
[1] => 10132200
[loan_number] => 10132200
[2] => 10000049
[loan_id] => 10000049
[3] => MONICA
[first_name] => MONICA
[4] => MERCHANT
[last_name] => MERCHANT
[5] => 2003-07-17 16:15:32
[approved_date] => 2003-07-17 16:15:32
[6] => ACH Debit
[type] => ACH Debit
)
[1] => Array
(
[0] => CHECKING
[ba_type] => CHECKING
[1] => 10154654
[loan_number] => 10154654
[2] => 10000055
[loan_id] => 10000055
[3] => RICH
[first_name] => RICH
[4] => LABO
[last_name] => LABO
[5] => 2003-07-17 16:15:32
[approved_date] => 2003-07-17 16:15:32
[6] => ACH Debit
[type] => ACH Debit
)
)
What I'd like to happen is first sort by ba_type, and then sort by
loan_number, so that I end up with a nice output similar to;
CHECKING 101234
CHECKING 101544
CHECKING 101573
SAVINGS 101112
SAVINGS 101224
VISA 101110
VISA 101998
Keep everything groupped together in their respective ba_type, and put the
numbers in numeric order. I've looked at usort, and many examples of it. I
can see how to use it to sort one column, but how would I sort a second to
achieve this?
-Dan Joseph
Dan Joseph Guest
-
Sorting array vs sorting paginated array
....pulling in a long list of photos in a gallery, and I have a sort function working within the pages of data fine. I need to bring it back out of... -
Sorting tree items manually
I am trying to allow the user a way of shifting through items in a tree 2 levels deep. This will give the user a chance to order the items within... -
Array Sorting
Hey everyone, I figured someone out there must have come across the need for this before, so rather than continue banging my head against the... -
client side sorting of datagrid items
Does anyone know if there's code out there to manage client-side sorting of datagrid items? I'd like to be able to fill a datagrid with records... -
[PHP] Array Sorting, 2 items...
> -----Original Message----- Well, erm, maybe I've got the wrong glasses on today, or maybe you've made a cut'n'paste boo-boo, but it sure looks... -
Marek Kilimajer #2
Re: [PHP] Array Sorting, 2 items...
Your array seems like a result of mysql_fetch_array(), cannot you order
it in the sql query?
Dan Joseph wrote:> Array
> (
> [0] => Array
> (
> [0] => CHECKING
> [ba_type] => CHECKING
> [1] => 10132200
> [loan_number] => 10132200Simply if ba_types are equal, continue with checking loan_numbers:> Keep everything groupped together in their respective ba_type, and put the
> numbers in numeric order. I've looked at usort, and many examples of it. I
> can see how to use it to sort one column, but how would I sort a second to
> achieve this?
function cmp ($a, $b) {
if ($a['ba_type'] == $b['ba_type']) {
if ($a['loan_number'] == $b['loan_number']) return 0;
return ($a['loan_number'] > $b['loan_number']) ? -1 : 1;
}
return ($a['ba_type'] > $b['ba_type']) ? -1 : 1;
}
Marek Kilimajer Guest
-
Dan Joseph #3
RE: [PHP] Array Sorting, 2 items...
Hi,
You know, this worked just fine, as did my order by. Its my brain that is
completely wacked. I am going about this all wrong....
Thanks for all your help.. Take care.. I'll let you know how it goes.
-Dan Joseph
> -----Original Message-----
> From: Marek Kilimajer [mailto:kilimajer@webglobe.sk]
> Sent: Tuesday, July 22, 2003 11:25 AM
> To: Dan Joseph
> Cc: [email]php-general@lists.php.net[/email]
> Subject: Re: [PHP] Array Sorting, 2 items...
>
>
> Your array seems like a result of mysql_fetch_array(), cannot you order
> it in the sql query?
>
> Dan Joseph wrote:>> > Array
> > (
> > [0] => Array
> > (
> > [0] => CHECKING
> > [ba_type] => CHECKING
> > [1] => 10132200
> > [loan_number] => 10132200> ba_type, and put the> > Keep everything groupped together in their respective> examples of it. I> > numbers in numeric order. I've looked at usort, and many> a second to> > can see how to use it to sort one column, but how would I sort> Simply if ba_types are equal, continue with checking loan_numbers:> > achieve this?
>
> function cmp ($a, $b) {
> if ($a['ba_type'] == $b['ba_type']) {
> if ($a['loan_number'] == $b['loan_number']) return 0;
> return ($a['loan_number'] > $b['loan_number']) ? -1 : 1;
> }
> return ($a['ba_type'] > $b['ba_type']) ? -1 : 1;
> }
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>Dan Joseph Guest



Reply With Quote

