[PHP-DB] Array sorting question...

2004-01-23 Thread NIPP, SCOTT V (SBCSI)
I am trying to populate an array from a MySQL database.  I think I
have the code correct to populate the array, but I need to somehow sort the
array eliminating duplicate values.  I think I can loop through the array
doing a comparison and building a new array by discarding the value if it is
a duplicate, but I was not sure if there was a more efficient way of doing
this.  I am already looping through the database query results, and I am
just thinking about efficiency here.
Here is a code sample with a little more description of what I am
attempting...

?php
  do {
$entry = $list['id_sys'];
$id = split('-', $list['id_sys'], 1);
$sbcuid = $id[0];
$users[] = '$sbcuid';  
  } while ($list = mysql_fetch_assoc($result));
?

This query pulls a value from the database that is a
username-hostname value.  What I am working on is building a page that has a
unique list of usernames that link to a second page of user account
information.  There may be twenty user account on different hosts for the
same username.  I only want to have the username link created once on this
page.  I hope that makes since to everyone.  Thanks in advance for any help.

Scott Nipp
Phone:  (214) 858-1289
E-mail:  [EMAIL PROTECTED]
Web:  http:\\ldsa.sbcld.sbc.com

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DB] Array sorting question...

2004-01-23 Thread Katie Evans-Young
NIPP, SCOTT V (SBCSI) wrote:
   I am trying to populate an array from a MySQL database.  I think I
 have the code correct to populate the array, but I need to somehow
 sort the array eliminating duplicate values.  I think I can loop
 through the array doing a comparison and building a new array by
 discarding the value if it is a duplicate, but I was not sure if
 there was a more efficient way of doing this.

You can ask for only unique values to be returned in the database result.

Try something like this:

$sql = SELECT UNIQUE username FROM table WHERE where_clause ORDER BY
username;

Katie Dewees
Web Developer/PHP Programmer
[EMAIL PROTECTED]
http://www.evans-young.com

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] array sorting

2002-11-12 Thread Martin Allan Jensen
Hi everyone...


I got a bit longer now..

But i have some trouble sorting my arrays

I get this array returned.

Array ( [0] = Array ( [0] = 10 [1] = 40 [2] = 50 [3] = 80 [4] = 130 [5] = 220 
[6] = 320 ) [1] = Array ( [0] = 10 [1] = 40 [2] = 50 [3] = 80 [4] = 130 [5] = 
220 [6] = 320 [7] = 440 [8] = 570 ) [2] = ) 

I ain't good at it, but i guess this is a two dimesioned array...

The question is now,  i need to get the highest values of each sub array witch would 
be 320  570 in THIS CASE ??

Thanks so much!!

Martin Allan Jensen


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] array sorting

2002-11-12 Thread Ignatius Reilly
Just loop through the first index, then search on the second index:

while ( list( $key, $value ) = each( $my_arr ) ) {

// now $value is your ( [0] = 10 [1] = 40 [2] = 50 [3] = 80 [4] =
130 [5] = 220 [6] = 320 ) array
// sort your array by values
sort( $value ) ;
// get the last value
$last_value = array_pop( $value ) ;
// do something with this value...

}

But it seems to me there still misses a link between your two series of data
(years, values)

So try to get an array where keys are years, not numerical indexes?

HTH
Ignatius

- Original Message -
From: Martin Allan Jensen [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Tuesday, November 12, 2002 1:37 PM
Subject: [PHP-DB] array sorting


Hi everyone...


I got a bit longer now..

But i have some trouble sorting my arrays

I get this array returned.

Array ( [0] = Array ( [0] = 10 [1] = 40 [2] = 50 [3] = 80 [4] = 130
[5] = 220 [6] = 320 ) [1] = Array ( [0] = 10 [1] = 40 [2] = 50 [3] =
80 [4] = 130 [5] = 220 [6] = 320 [7] = 440 [8] = 570 ) [2] = )

I ain't good at it, but i guess this is a two dimesioned array...

The question is now,  i need to get the highest values of each sub array
witch would be 320  570 in THIS CASE ??

Thanks so much!!

Martin Allan Jensen


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php