Re: PHP sort from .... best solution?
| From: | A. Lyse | Date: | Wed, 04 Jun 2003 11:40:44 +0000 |
| Subject: | Re: PHP sort from .... best solution? | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-28296@lists.php.net to get a copy of this message | ||
Hi again!
I talked to the admin guy and he said there is an easyer way to do this (as
usual he doenst have the time to show me) so I try here:
He gave me a liddle example in c and a light translation to PHP:
Bubble sort (exampel written in c, but can "easyly" be translated to php):
for (i=0; i<n-1; i++) {
for (j=0; j<n-1-i; j++)
if (a[j+1] < a[j]) { /* compare the two neighbors */
tmp = a[j]; /* swap a[j] and a[j+1] */
a[j] = a[j+1];
a[j+1] = tmp;
}
}
**************
More example of Bubble Sort:
http://www.cs.ust.hk/faculty/tcpong/cs102/summer96/aids/bubble.html
The if-sentense must here be written to
if($a[$j+1]->publisertLang < $a[$j]->publisertLang)
where a is $ingresser and $n is the number of elements in $ingresser.
I
The if sentese is going in the php file pastet yesterday.
Not that yeasterdays metod did'nt work, but if somebody has an idea on this
one and can give me a full example based on the info i've pastet yesterday
it would be great!
Regards,
A. Lyse