PHP.mk документација

ldap_sort

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

function.ldap-sort.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека function.ldap-sort.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
ldap_sort

Референца за `function.ldap-sort.php` со подобрена типографија и навигација.

function.ldap-sort.php

ldap_sort

(PHP 4 >= 4.2.0, PHP 5, PHP 7)

ldap_sort(PHP 4 >= 4.2.0, PHP 5, PHP 7)

Ги ескејпува специјалните знаци во стринг за употреба во SQL изјава

Оваа функција е DEPRECATED Сортирај ги резултатите од LDAP на страна на клиентот REMOVED од PHP 8.0.0. Силно се обесхрабрува потпирањето на оваа функција.

= NULL

ldap_sort(resource $link, resource $result, string $sortfilter): bool

од PHP 7.0.0 и ldap_search().

Сортирај го резултатот од LDAP пребарување, вратен од sizelimit Бидејќи оваа функција ги сортира вратените вредности на страна на клиентот, можно е да не ги добиете очекуваните резултати во случај да достигнете ldap_search().

Параметри

link

Земи ги информациите за пагинација испратени од серверот. ldap_connect().

result

или на серверот или дефинирано во ldap_search().

sortfilter

Идентификатор на резултат од пребарување, вратен од

Вратени вредности

Не се враќа вредност.

Дневник на промени

Верзија = NULL
8.0.0 Оваа функција е отстранета.

Примери

Атрибутот што треба да се користи како клуч во сортирањето.

Сортирање на резултатот од пребарување.

<?php
// $ds is a valid link identifier (see ldap_connect)

$dn = 'ou=example,dc=org';
$filter = '(|(sn=Doe*)(givenname=John*))';
$justthese = array('ou', 'sn', 'givenname', 'mail');

$sr = ldap_search($ds, $dn, $filter, $justthese);

// Sort
ldap_sort($ds, $sr, 'sn');

// Retrieving the data
$info = ldap_get_entries($ds, $sr);

Белешки од корисници 6 белешки

Пример #1 LDAP сортирање
21 години пред
This note may be self-evident, but the functionality of ldap_sort threw off this sometime user of relational databases.

The following code will NOT do what you expect:

<?php

// omitted calls to connect and and bind to LDAP server...

// attributes we want to retrieve from LDAP server
$ldap_attributes = array ( 'cn', 'o', 'mail' ) ;

// retrieve attributes from matching entries
$search_results = ldap_search ( $ldap_conn, 'dc=example,dc=org', '(objectclass=*)', 0, 500, 30 ) ;

// sort entries by last name ('sn')
ldap_sort ( $ldap_conn, $search_results, 'sn' ) ;

?>

The entries will NOT be sorted by last name. Why not? Because LDAP doesn't function like a RDBMS; you cannot sort a result set on an arbitrary field, regardless of whether you "selected" it. You must always include the attribute by which you want to sort your entries among the requested attributes (add 'sn' to $ldap_attributes, in this case).

Hope this is helpful to some other folks who scratched their heads when they tried to sort entries and it didn't work out...
zbaizman at yahoo dot com
пред 15 години
I wondered how to sort after a dn, for just show a tree view. I tried to set $sortfilter = 'dn', but that didn't work. Than I tried with a blank string ''. That worked, the entries are sorted by dn.
thorben at kapp-hamburg dot de
21 години пред
If you are wanting to sort by multiple attributes, for instance ordering by last name and then first name,  try this function. This is similar to "ORDER BY lastname, firstname"  in SQL.

This function uses an insertion sort algorithm, which is somewhat faster then the old-fashoned bubble sort.  The second argument is an array containing the attributes you want to sort by. (this functon won't do descending or ascending..  feel free to add it!)

<?php
/**
 * @param array $entries
 * @param array $attribs
 * @desc Sort LDAP result entries by multiple attributes.
*/
function ldap_multi_sort(&$entries, $attribs){
    for ($i=1; $i<$entries['count']; $i++){
        $index = $entries[$i];
        $j=$i;
        do {
            //create comparison variables from attributes:
            $a = $b = null;
            foreach($attribs as $attrib){
                $a .= $entries[$j-1][$attrib][0];
                $b .= $index[$attrib][0];
            }
            // do the comparison
            if ($a > $b){
                $is_greater = true;
                $entries[$j] = $entries[$j-1];
                $j = $j-1;
            }else{
                $is_greater = false;
            }
        } while ($j>0 && $is_greater);
        
        $entries[$j] = $index;
    }
    return $entries;
}
?>
ben at xsusio dot com
пред 22 години
Here's a simple LDAP sort function I wrote:

<?php
function sort_ldap_entries($e, $fld, $order)
{
    for ($i = 0; $i < $e['count']; $i++) {
        for ($j = $i; $j < $e['count']; $j++) {
            $d = strcasecmp($e[$i][$fld][0], $e[$j][$fld][0]);
            switch ($order) {
            case 'A':
                if ($d > 0)
                    swap($e, $i, $j);
                break;
            case 'D':
                if ($d < 0)
                    swap($e, $i, $j);
                break;
            }
        }
    }
    return ($e);
}

function swap(&$ary, $i, $j)
{
    $temp = $ary[$i];
    $ary[$i] = $ary[$j];
    $ary[$j] = $temp;
}
?>

so that it can be invoked like:

<?php
    $entries = sort_ldap_entries($entries, 'mail', 'A'); // sort entries by ascending order of mail
?>

where,
    `$entries' is the array returned by ldap_get_entries() function.

This might be useful to those who still run older versions of PHP (<= 4.2.0) on their web servers :-)
askgopal at sify dot com
пред 23 години
This function applies strcmp() to each attribute (given by sortfilter) in order to sort the entries returned by the server.  To order search results ascending by last name, try passing "sn" as the sortfilter argument.  This function does not play nice with multi-valued attributes.
matthew dot j dot gray at uwrf dot edu
пред 23 години
Something real simple i wrote to sort directory searches by a persons last name.

<?php
for($i=0;$i<$result["count"];$i++)
{

$lastname = $result[$i]["sn"][0];

$lnames["$i"]=$lastname;

}//for i

@asort($lnames);
?>
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.