Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [SQL]Łączenie tabel z warunkiem/problem w stronicowaniu
eurosoft
post
Post #1





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

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


Mam poblem z łączeniem tabel, w sumie to wszystko ładnie działało, zapytania, stronicowanie, jednak potrzebowałem zawęzić pole zapytania warunkiem i wszystko wzięło w łeb. Otórz mam takie zapytania:
  1. $sql = "SELECT COUNT(*) FROM $tabela";
  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 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.id_book>$from";
  23. $result1 = mysql_query($sql1) OR die('Queryproblem: '.mysql_error());
  24.  

wszytsko ładnie działa, jednak potrzebuję użyć warunku w zapytaniach filtrując dane w tabeli $tabela po kolumnie nr_obw więc zrobiłem:
  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.  

i po takiej operacji w łeb wzięło prawidłowe stronicowanie, rekordy dodają się nie tam gdzie powinny

proszę o radę bo już oczy wypatrzyłem i nic nie mogę znaleźć.
P.s. jeśli stronicowanie mieści się na jednej stronie to jest ok

Ten post edytował eurosoft 3.12.2010, 19:42:14
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: 22.08.2025 - 14:43