Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [mysql]Łączenie dwóch tabel
eldo
post 26.01.2008, 20:07:51
Post #1





Grupa: Zarejestrowani
Postów: 19
Pomógł: 0
Dołączył: 28.08.2007
Skąd: Cardiff

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


Posiadam dwie tabele:

Tabela1 -> | pole1 | pole2 | pole3 |

Tabela2 -> | pole1 | pole2 | pole3 |

A teraz moje pytanko: musze na stronie wyświetlić wszystkie pola z odpowiednich wierszy gdzie np. Tabela1.pole1 = Tabela2.pole1
Z góry wielkie thx.
Powód edycji: dodalem tag (cysiaczek)
Go to the top of the page
+Quote Post
webdice
post 26.01.2008, 20:10:24
Post #2


Developer


Grupa: Moderatorzy
Postów: 3 045
Pomógł: 290
Dołączył: 20.01.2007




  1. SELECT * FROM `tabela1`, `tabela2`
Go to the top of the page
+Quote Post
arecki
post 26.01.2008, 20:12:47
Post #3





Grupa: Zarejestrowani
Postów: 222
Pomógł: 35
Dołączył: 6.02.2005

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


Oj chyba nie o to chodziło. Bardziej już o to:

  1. SELECT tab1.*, tab2.* FROM tabela1 tab2 LEFT JOIN tabela2 tab2 WHERE tab1.pole1 = tab2.pole1


--------------------
Go to the top of the page
+Quote Post
webdice
post 26.01.2008, 20:18:35
Post #4


Developer


Grupa: Moderatorzy
Postów: 3 045
Pomógł: 290
Dołączył: 20.01.2007




Cytat(arecki @ 26.01.2008, 20:12:47 ) *
Oj chyba nie o to chodziło.


Nie doczytałem o tym warunku smile.gif.

P.S. Podałeś zły alias dla pierwszej tabeli.
Go to the top of the page
+Quote Post
eldo
post 26.01.2008, 20:23:11
Post #5





Grupa: Zarejestrowani
Postów: 19
Pomógł: 0
Dołączył: 28.08.2007
Skąd: Cardiff

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


Pisze tak:

SELECT tabela1.*, tabela2.* FROM tabela1 tabela2 LEFT JOIN tabela2 tabela2 WHERE tabela1.pole1 = tabela2.pole1

i wywali mi Warning: mysqli::query() ....... Couldn't fetch mysqli in

Ten post edytował eldo 26.01.2008, 21:04:23
Go to the top of the page
+Quote Post
webdice
post 26.01.2008, 21:54:38
Post #6


Developer


Grupa: Moderatorzy
Postów: 3 045
Pomógł: 290
Dołączył: 20.01.2007




  1. SELECT tabela1.*, tabela2.* FROM tabela1 LEFT JOIN tabela2 ON tabela1.pole1 = tabela2.pole1
Go to the top of the page
+Quote Post
eldo
post 27.01.2008, 20:06:24
Post #7





Grupa: Zarejestrowani
Postów: 19
Pomógł: 0
Dołączył: 28.08.2007
Skąd: Cardiff

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


Dzięki chłopaki za pomoc. Obydwaj dobrze radziliście. Problemem było zamknięcie połączenia z bazą wyżej w skrypcie. Takie małe przeoczenie. sciana.gif
Plusiki poszły! Pozdrowionka
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 Wersja Lo-Fi Aktualny czas: 16.06.2025 - 22:55