[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