Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [mysql] Sortowanie - najpierw konkretne ID
pieto
post
Post #1





Grupa: Zarejestrowani
Postów: 227
Pomógł: 1
Dołączył: 12.05.2002
Skąd: gdańsk

Ostrzeżenie: (0%)
-----


Witam

czy jest sposob aby posortowac tablice najpier po konkretnym id a nastepnie np po nazwie ?

czyli na gore trafia jeden konkretny rekord, reszta po nazwie ?
Go to the top of the page
+Quote Post
deirathe
post
Post #2





Grupa: Zarejestrowani
Postów: 426
Pomógł: 32
Dołączył: 24.05.2007

Ostrzeżenie: (0%)
-----


spróbuj stworzyć własną funkcje sortującą i użyć user_sort();
Go to the top of the page
+Quote Post
pieto
post
Post #3





Grupa: Zarejestrowani
Postów: 227
Pomógł: 1
Dołączył: 12.05.2002
Skąd: gdańsk

Ostrzeżenie: (0%)
-----


niestety za duzo przerobek mi z tego wyniknie, na samym mysql'u nie idzie ?
Go to the top of the page
+Quote Post
UDAT
post
Post #4





Grupa: Zarejestrowani
Postów: 442
Pomógł: 0
Dołączył: 27.12.2005

Ostrzeżenie: (0%)
-----


Jeśli chodzi ci o wyciągnięcie rekordu o najmniejszym ID, a potem reszty według nazwy, to spróbuj czegoś takiego :
  1. SELECT * FROM tabela WHERE /*** Ograniczenie **/ ORDER BY id LIMIT 1
  2. UNION
  3. SELECT * FROM tabela WHERE ( /*** Ograniczenie **/ ) AND id!=( SELECT * FROM tabela WHERE /*** Ograniczenie **/ ORDER BY id LIMIT 1) ORDER BY name


Ten post edytował UDAT 29.06.2007, 17:50:15
Go to the top of the page
+Quote Post
pieto
post
Post #5





Grupa: Zarejestrowani
Postów: 227
Pomógł: 1
Dołączył: 12.05.2002
Skąd: gdańsk

Ostrzeżenie: (0%)
-----


Id wcale nie jest najmniejsze (IMG:http://forum.php.pl/style_emoticons/default/sad.gif)

jest na zmiennej i wacha sie od 1 do konca
Go to the top of the page
+Quote Post
UDAT
post
Post #6





Grupa: Zarejestrowani
Postów: 442
Pomógł: 0
Dołączył: 27.12.2005

Ostrzeżenie: (0%)
-----


To może ci chodzi o:
  1. .... ORDER BY id, name
Go to the top of the page
+Quote Post
pieto
post
Post #7





Grupa: Zarejestrowani
Postów: 227
Pomógł: 1
Dołączył: 12.05.2002
Skąd: gdańsk

Ostrzeżenie: (0%)
-----


raczej o ORDER BY id = 111, name

gdyby tak mozna bylo
Go to the top of the page
+Quote Post
Kicok
post
Post #8





Grupa: Zarejestrowani
Postów: 1 033
Pomógł: 125
Dołączył: 17.09.2005
Skąd: Żywiec

Ostrzeżenie: (0%)
-----


  1. ( SELECT * FROM tabela WHERE ( id = 4 ) )
  2. UNION
  3. ( SELECT * FROM tabela WHERE (id != 4) ORDER BY name ASC )



Zamiast 4 wstawiasz sobie swoje wybrane ID
Go to the top of the page
+Quote Post
pieto
post
Post #9





Grupa: Zarejestrowani
Postów: 227
Pomógł: 1
Dołączył: 12.05.2002
Skąd: gdańsk

Ostrzeżenie: (0%)
-----


no no...
Problem w tym ze mam bardziej skomplikowane zapytanie (w funkcji rekurencyjnej do budowania menu)

dałem tak, ale cos jest nie teges - wyrzuca NIC, czyli biala strone

  1. <?php
  2. $categories_query = tep_db_query("select c.categories_id,c.art_producent , c.art , c.categories_status, cd.categories_name, cd.categories_htc_keywords_tag, c.paren
    t_id from "
     . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd  where c.categories_id = 102 UNION  select c.categories_id,c.art_producent , c.art , c.categories_status, cd.categories_name, cd.categories_htc_keywords_tag, c.paren
    t_id from "
     . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = " . (int)$value . " and c.categories_status>0 and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by c.sort_order, cd.categories_name");
  3. ?>
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 24.08.2025 - 00:00