Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [SQL]Złe wartości w łączeniu rekordów 2 tabel
eurosoft
post
Post #1





Grupa: Zarejestrowani
Postów: 179
Pomógł: 0
Dołączył: 5.11.2010

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


Proszę o pomoc w kodzie, po dodaniu warunku WHERE $tabela.nr_obw='{$_SESSION['nr_obw']}' rekordy się mieszają

  1. $sql = "SELECT COUNT(*) FROM $tabela WHERE nr_obw='{$_SESSION['nr_obw']}'";
  2. $result = mysql_query($sql) OR die('Queryproblem: ' . mysql_error());
  3. $ilePozycji = mysql_result($result, 0);
  4. mysql_free_result($result);
  5.  
  6. $sql = "SELECT * FROM $tabela WHERE nr_obw='{$_SESSION['nr_obw']}' LIMIT $from, $ileNaStronie";
  7. $result = mysql_query($sql) OR die('Queryproblem: '.mysql_error());
  8. $zlicz = mysql_num_rows($result);
  9.  
  10. $sql1 = "SELECT
  11. $tabela.id_book,
  12. $tabela.imie_nazwisko,
  13. $tabela.start_pol,
  14. $tabela1.animals,
  15. $tabela1.animals1,
  16. $tabela1.animals2,
  17. $tabela1.ilosc,
  18. $tabela1.ilosc1,
  19. $tabela1.ilosc2,
  20. $tabela1.ilosc_shot,
  21. $tabela1.login
  22. FROM $tabela LEFT JOIN shot ON $tabela.id_book=$tabela1.id_book WHERE $tabela.nr_obw='{$_SESSION['nr_obw']}' and $tabela.id_book>$from";
  23. $result1 = mysql_query($sql1) OR die('Queryproblem: '.mysql_error());
  24.  
Go to the top of the page
+Quote Post
Smertius
post
Post #2





Grupa: Zarejestrowani
Postów: 156
Pomógł: 31
Dołączył: 23.02.2009
Skąd: Sanok

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


Co rozumiesz pod pojęciem "rekordy się mieszają"?

Do sortowania służy ORDER BY
Go to the top of the page
+Quote Post
eurosoft
post
Post #3





Grupa: Zarejestrowani
Postów: 179
Pomógł: 0
Dołączył: 5.11.2010

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


Cytat(Smertius @ 3.12.2010, 21:00:02 ) *
Co rozumiesz pod pojęciem "rekordy się mieszają"?

Do sortowania służy ORDER BY

w jednej tabeli ($tabela)mam różne pola które powinny się połączyć z polami innej tabeli($tabela1) łącznikiem jest pole id_book.
jednak po zastosowaniu warunku pola łączone sią bez uwzględnianie id_book
Go to the top of the page
+Quote Post
tomm
post
Post #4





Grupa: Zarejestrowani
Postów: 142
Pomógł: 28
Dołączył: 7.04.2008

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


spróbuj tak:

CODE
$sql1 = sprintf("SELECT t1.id_book, t1.imie_nazwisko, t1.start_pol, t2.animals, t2.animals1, t2.animals2, t2.ilosc, t2.ilosc1, t2.ilosc2, t2.ilosc_shot, t2.login
FROM $tabela t1 LEFT JOIN shot t2 USING(id_book) WHERE t1.nr_obw= %d and t1.id_book > %d",
$_SESSION['nr_obw'], $from);
Go to the top of the page
+Quote Post
eurosoft
post
Post #5





Grupa: Zarejestrowani
Postów: 179
Pomógł: 0
Dołączył: 5.11.2010

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


Cytat(tomm @ 3.12.2010, 23:47:25 ) *
spróbuj tak:

CODE
$sql1 = sprintf("SELECT t1.id_book, t1.imie_nazwisko, t1.start_pol, t2.animals, t2.animals1, t2.animals2, t2.ilosc, t2.ilosc1, t2.ilosc2, t2.ilosc_shot, t2.login
FROM $tabela t1 LEFT JOIN shot t2 USING(id_book) WHERE t1.nr_obw= %d and t1.id_book > %d",
$_SESSION['nr_obw'], $from);


(IMG:style_emoticons/default/sad.gif) NIESTETY TO SAMO.....
Go to the top of the page
+Quote Post

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: 24.08.2025 - 20:02