CollectionFind::sort

(No version information available, might only be in Git)

CollectionFind::sortSet the sorting criteria

Beschreibung

public mysql_xdevapi\CollectionFind::sort(string $sort_expr): mysql_xdevapi\CollectionFind

Sort the result set by the field selected in the sort_expr argument. The allowed orders are ASC (Ascending) or DESC (Descending). This operation is equivalent to the 'ORDER BY' SQL operation and it follows the same set of rules.

Parameter-Liste

sort_expr

One or more sorting expressions can be provided. The evaluation is from left to right, and each expression is separated by a comma.

Rückgabewerte

A CollectionFind object that can be used to execute the command, or to add additional operations.

Beispiele

Beispiel #1 mysql_xdevapi\CollectionFind::sort() example

<?php
$session 
mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$session->sql("DROP DATABASE IF EXISTS addressbook")->execute();
$session->sql("CREATE DATABASE addressbook")->execute();

$schema $session->getSchema("addressbook");
$create $schema->createCollection("people");
$create
  
->add('{"name": "Alfred", "age": 18, "job": "Butler"}')
  ->
execute();
$create
  
->add('{"name": "Reginald", "age": 42, "job": "Butler"}')
  ->
execute();

// ...

$collection $schema->getCollection("people");

$result $collection
  
->find()
  ->
sort('job desc''age asc')
  ->
execute();

var_dump($result->fetchAll());
?>

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

array(2) {
  [0]=>
  array(4) {
    ["_id"]=>
    string(28) "00005b6b53610000000000000106"
    ["age"]=>
    int(18)
    ["job"]=>
    string(6) "Butler"
    ["name"]=>
    string(6) "Alfred"
  }
  [1]=>
  array(4) {
    ["_id"]=>
    string(28) "00005b6b53610000000000000107"
    ["age"]=>
    int(42)
    ["job"]=>
    string(6) "Butler"
    ["name"]=>
    string(8) "Reginald"
  }
}

Hier Kannst Du einen Kommentar verfassen


Bitte gib mindestens 10 Zeichen ein.
Wird geladen... Bitte warte.
* Pflichtangabe
Es sind noch keine Kommentare vorhanden.

Was genau bedeutet "Vibe Coding"? Ein tiefgehender Blick für Entwickler

In der Welt der Softwareentwicklung gibt es unzählige Wege, wie man an ein Projekt herangeht. Manche schwören auf strikte Planung, andere auf bewährte Algorithmen und wieder andere lassen sich von etwas ganz anderem leiten: ihrem Gefühl. ...

admin

Autor : admin
Kategorie: Software & Web-Development

PHP cURL-Tutorial: Verwendung von cURL zum Durchführen von HTTP-Anfragen

cURL ist eine leistungsstarke PHP-Erweiterung, die es Ihnen ermöglicht, mit verschiedenen Servern über verschiedene Protokolle wie HTTP, HTTPS, FTP und mehr zu kommunizieren. ...

TheMax

Autor : TheMax
Kategorie: PHP-Tutorials

Midjourney Tutorial - Anleitung für Anfänger

Über Midjourney, dem Tool zur Erstellung digitaler Bilder mithilfe von künstlicher Intelligenz, gibt es ein informatives Video mit dem Titel "Midjourney Tutorial auf Deutsch - Anleitung für Anfänger" ...

Mike94

Autor : Mike94
Kategorie: KI Tutorials

Tutorial veröffentlichen

Tutorial veröffentlichen

Teile Dein Wissen mit anderen Entwicklern weltweit

Du bist Profi in deinem Bereich und möchtest dein Wissen teilen, dann melde dich jetzt an und teile es mit unserer PHP-Community

mehr erfahren

Tutorial veröffentlichen

Hilfe mit PHP und MySQL

Having trouble connecting to my MySQL database with PHP! Anyone else faced this? I did; turns out, I had the wrong port number in my connection st ...

Geschrieben von JohnTaylor am 24.05.2025 08:57:33
Forum: PHP Developer Forum
Grid und Pos geht nicht ...

Silder1 soll in Reihe 5 und Spalte 2 bis 6 einnehmen. Silder2 soll in Reihe 6 und Spalte 2 bis 5 einnehmen. https://handicap-fan.com/test.html w ...

Geschrieben von tomycat am 23.05.2025 14:12:36
Forum: PHP Developer Forum
Grid und Pos geht nicht ...

Silder 1 soll sich von Grid Spalte 2 bis 5 und Spalte 5 einnehmen, was muss ich ändern? Silder 2 soll sich von Grid Spalte 2 bis 4 und Spalte 6 e ...

Geschrieben von tomycat am 23.05.2025 14:09:48
Forum: PHP Developer Forum
How Clean SQL Architecture Saves You From Technical Debt

Once I realized I could offload repeat logic to SQL views, my PHP Infinite Craft​ (https://infinitecraftrecipes.io) code started looking more li ...

Geschrieben von bekeanloinse56 am 20.05.2025 05:16:28
Forum: SQL / Datenbanken