Mailinglisten-Archive |
Stephan Noller wrote: > ich moechte einen DB-Inhalt nach Wochentagen sortiert ausgeben. Da mir mit > SQL keine Loesung einfaellt, dachte ich mir ich baue eine Schleife die an > die SQL-Abfrage jeweils den Wochentag uebergibt. In MySQL: http://www.mysql.com/Manual_chapter/manual_Reference.html#String_functions ELT(N,str1,str2,str3,...) Returns str1 if N = 1, str2 if N = 2, and so on. Returns NULL if N is less than 1 or greater than the number of arguments. ELT() is the complement of FIELD(). mysql> select ELT(1, 'ej', 'Heja', 'hej', 'foo'); -> 'ej' mysql> select ELT(4, 'ej', 'Heja', 'hej', 'foo'); -> 'foo' FIELD(str,str1,str2,str3,...) Returns the index of str in the str1, str2, str3, ... list. Returns 0 if str is not found. FIELD() is the complement of ELT(). mysql> select FIELD('ej', 'Hej', 'ej', 'Heja', 'hej', 'foo'); -> 2 mysql> select FIELD('fo', 'Hej', 'ej', 'Heja', 'hej', 'foo'); -> 0 mysql> create table gurke ( -> bla int, -> wkday varchar(2)); Query OK, 0 rows affected (0.13 sec) mysql> insert into gurke values ( 2, "Di"); Query OK, 1 row affected (0.00 sec) mysql> insert into gurke values ( 3, "Mo"); Query OK, 1 row affected (0.00 sec) mysql> select *, field(wkday, "Mo", "Di", "Mi", "Do", "Fr", "Sa", "So") as day f rom gurke order by day; +------+-------+-----+ | bla | wkday | day | +------+-------+-----+ | 3 | Mo | 1 | | 2 | Di | 2 | | 1 | Do | 4 | +------+-------+-----+ 3 rows in set (0.00 sec) mysql> drop table gurke; Query OK, 0 rows affected (0.06 sec) -- Kristian Köhntopp, NetUSE Kommunikationstechnologie GmbH Siemenswall, D-24107 Kiel, Germany, +49 431 386 436 00 Using PHP3? See our web development library at http://phplib.netuse.de/ (We have moved! Update your bookmarks!)
php::bar PHP Wiki - Listenarchive