Re: Newbie with sorting problem

From: Date: Tue, 06 Jan 2004 12:43:38 +0000
Subject: Re: Newbie with sorting problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-173843@lists.php.net to get a copy of this message
Hello Bart, Tuesday, January 6, 2004, 12:40:38 PM, you wrote: BK> This scripts works, but.. my desire is now to be able to sort the BK> output, wich is generated by the 'while' loop, for instance on 'name', BK> or on 'surname' . sort(), ksort()? I couldn't understand the BK> explanations i found (and so declared myself as newbie :) It's probably a lot easier to sort the data at the SQL level rather than messing around with your array. For example: $result = mysql_query( "SELECT id, name, surname, address FROM addresses ORDER BY name DESC"); Will list by name alphabetically (A-Z), change to "ASC" for Z-A). You can also order by two fields at once: $result = mysql_query( "SELECT id, name, surname, address FROM addresses ORDER BY name DESC, surname DESC"); Or some selective sorting: $result = mysql_query( "SELECT id, name, surname, address FROM addresses WHERE name LIKE 'a%' ORDER BY name DESC"); Will list all names starting with the letter A, in alphabetical order. -- Best regards, Richard mailto:rich@launchcode.co.uk

« previous php.general (#173843) next »