Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> lista w mysql, cd
kicaj
post
Post #1





Grupa: Zarejestrowani
Postów: 1 640
Pomógł: 28
Dołączył: 13.02.2003
Skąd: Międzyrzecz/Poznań

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


Tabela: posts
post_id int auto_i...
post_title var..
post_content text...
post_user_id int...
post_parent_id

Wybrac najnowsze posty, wyswietlajac `post_title` rodzica (`post_parent_id`)

Udalo mi sie to wykonac, ale jesli byl post bez odpowiedzi to sie sypalo...
JTZ?

Ten post edytował kicaj_ 12.02.2005, 01:25:36
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
popbart
post
Post #2





Grupa: Zarejestrowani
Postów: 255
Pomógł: 0
Dołączył: 22.04.2004
Skąd: Żoliborz

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


  1. SELECT t1.post_title AS title_rodzic,t2.post_title AS title_dziecko
  2. FROM posts AS t1 RIGHT JOIN posts AS t2 ON(t2.post_parent_id=t1.post_id)

Wyjaśnienie- rodzic to dziecko bez rodzica (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Jeżeli chcesz odwrotnie to:
  1. SELECT IF(t1.post_title IS NULL,t2.post_title,t1.post_title) AS title_rodzic,
  2. IF(t1.post_title IS NULL,NULL,t2.post_title) AS title_dziecko
  3. FROM posts AS t1 RIGHT JOIN posts AS t2 ON(t2.post_parent_id=t1.post_id)
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 5.10.2025 - 01:35