Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP]Jak pobrać wyniki z 2 tabel jednocześnie (łączenie wyników)
-Mielito-
post
Post #1





Goście







Witam,

Pobieram dane z 2 tabel w taki sposób:

  1. $sql = 'SELECT nazwa, opis FROM `tabela1` WHERE id > 0;' ;
  2.  
  3.  
  4. $resultx = mysql_query($sql);
  5.  
  6.  
  7. if(mysql_num_rows($resultx) > 0) {
  8.  
  9.  
  10. while($row123 = mysql_fetch_assoc($resultx)) {
  11.  
  12.  
  13.  
  14. }
  15.  
  16. echo $nazwa . " - " . $opis;
  17.  
  18. }
  19.  
  20.  
  21.  
  22.  
  23.  
  24. [php]$sql = 'SELECT nazwa, opis FROM `tabela2` WHERE id > 0;' ;
  25.  
  26.  
  27. $resultx = mysql_query($sql);
  28.  
  29.  
  30. if(mysql_num_rows($resultx) > 0) {
  31.  
  32.  
  33. while($row123 = mysql_fetch_assoc($resultx)) {
  34.  
  35.  
  36.  
  37. }
  38.  
  39. echo $nazwa . " - " . $opis;
  40.  
  41. }


[/php]


W tym momencie chciałbym aby dane z obu tabel zostały połączone, tzn znajdowały się w jednej tablicy.
Jak to zrobić ?

(pewnie można to zrobić bezpośrednio z sql jak i połączyć wyniki po pobraniu osobnymi zapytaniami j/w, ale nie mogę sobie z tym poradzić)
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
peter13135
post
Post #2





Grupa: Zarejestrowani
Postów: 1 447
Pomógł: 191
Dołączył: 26.03.2008

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


left joinem możesz łączyć kilka tabel (IMG:style_emoticons/default/smile.gif)
poza tym, może takie coś ?
[sql]select t1.*, t2.id, t3.name, t4.value from tabela1 as t1, tabela2 as t2, tabela3 as t3, tabela4 as t4 where t1.id = t3.id_czegośtam[/code]
Go to the top of the page
+Quote Post

Posty w temacie


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: 3.10.2025 - 17:28