Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL] Dane z 2 tabel
Micchaleq
post
Post #1





Grupa: Zarejestrowani
Postów: 186
Pomógł: 4
Dołączył: 13.10.2009

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


Witam serdecznie,

Mam 2 tabele :

1 users :
-user_id
-username
-user_password

2. user_groups
-group_id
-user_id

chcę wyświetlić wszystkie group_id dla danego użytkownika:

Próbowałem tak :
  1. $sql = "SELECT u.username, u.user_password, ug.user_id, g.group_id from ".USERS_TABLE." u, left join ".USERS_GROUPS_TABLE." g WHERE u.username = '".$username."' AND u.user_id = g.user_id";


Ktoś pomoże?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Micchaleq
post
Post #2





Grupa: Zarejestrowani
Postów: 186
Pomógł: 4
Dołączył: 13.10.2009

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


Witam ponownie,

ktoś może udzielić odpowiedzi dlaczego i gdzie to jest błędne?
mam 3 tabele :
użytkownicy - user_id, username
użytkownicy_grupy - user_id, group_id
grupy - group_id , group_name

"SELECT *
FROM ".USERS_TABLE." u
LEFT JOIN ".USERS_GROUPS_TABLE." p ON u.user_id = p.user_id
LEFT JOIN ".GROUPS_TABLE." g ON p.group_id = g.group_id
WHERE u.username = '".$username."'"

i nie zwraca żadnego pola dla danego użytkownika chociaż wiem że coś powinno być.
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: 11.10.2025 - 19:27