Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

2 Stron V   1 2 >  
Reply to this topicStart new topic
> Pobieranie 20k rekordów
slawek19926
post
Post #1





Grupa: Zarejestrowani
Postów: 33
Pomógł: 0
Dołączył: 29.07.2016

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


Witam.

Mam poważny problem. W bazie danych znajduje sie 12k+ rekordów i mam problem z wyświetleniem wszystkich rekordów (wyświetlają się, ale trwa to bardzo długo)

KOD strony.

Proszę o pomoc.

P.S.
Nie chcę rezygnować z dataTables.js
Go to the top of the page
+Quote Post
kapslokk
post
Post #2





Grupa: Zarejestrowani
Postów: 965
Pomógł: 285
Dołączył: 19.06.2015
Skąd: Warszawa

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


Się nie dziwie, że trwa to długo, przeglądarka ma problem z taką duża ilościa danych.
Google -> datatables.js large data i 2 link
Go to the top of the page
+Quote Post
slawek19926
post
Post #3





Grupa: Zarejestrowani
Postów: 33
Pomógł: 0
Dołączył: 29.07.2016

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


Kod teraz wygląda tak i nadal jest problem :/
Go to the top of the page
+Quote Post
nospor
post
Post #4





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Nadal na raz pobierasz wszystkie dane z bazy... Zrozum, nie mozesz pobierac wszystkich danych i ich naraz wyswietlac.
Go to the top of the page
+Quote Post
slawek19926
post
Post #5





Grupa: Zarejestrowani
Postów: 33
Pomógł: 0
Dołączył: 29.07.2016

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


To właśnie wiem, tylko nie wiem jak to ustawić. Jak ustawię LIMIT to na nic mi się to zda bo nie zobaczę wszystkich rekordów :/
Go to the top of the page
+Quote Post
nospor
post
Post #6





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




No i wlasnie dlatego ajaxem miales zapodowac kolejne dane dla danej strony. A zamiast tego na zywca bez namyslu skopiowales przyklad do ktorego cie odeslano
Go to the top of the page
+Quote Post
slawek19926
post
Post #7





Grupa: Zarejestrowani
Postów: 33
Pomógł: 0
Dołączył: 29.07.2016

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


Kombinuje ale za chińca niemam pojęcia jak (IMG:style_emoticons/default/sad.gif)
Go to the top of the page
+Quote Post
nospor
post
Post #8





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Ten przyklad wydaje sie lepszy
https://datatables.net/examples/server_side/post.html

tylko ze ty masz tam wygenerowac dane z bazy a nie z tego co oni tam maja po stronie serwera. Od ktorego rekordu masz zaczac wysyla ci to w POST.
Go to the top of the page
+Quote Post
slawek19926
post
Post #9





Grupa: Zarejestrowani
Postów: 33
Pomógł: 0
Dołączył: 29.07.2016

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


Dobrze rozumiem, że muszę zrezygnować z np:
  1. echo "<td>".$row['nazwa']."</td>";
itd?
Go to the top of the page
+Quote Post
nospor
post
Post #10





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Tak, masz zwracac teraz dane dla ajaxa czyli JSON. Na stronie masz przyklad jaki to ma byc JSON konkretnie
Go to the top of the page
+Quote Post
slawek19926
post
Post #11





Grupa: Zarejestrowani
Postów: 33
Pomógł: 0
Dołączył: 29.07.2016

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


Czyli muszę skorzystać z tego?
  1. <?php
  2.  
  3. /*
  4.  * DataTables example server-side processing script.
  5.  *
  6.  * Please note that this script is intentionally extremely simply to show how
  7.  * server-side processing can be implemented, and probably shouldn't be used as
  8.  * the basis for a large complex system. It is suitable for simple use cases as
  9.  * for learning.
  10.  *
  11.  * See <a href="http://datatables.net/usage/server-side" target="_blank">http://datatables.net/usage/server-side</a> for full details on the server-
  12.  * side processing requirements of DataTables.
  13.  *
  14.  * @license MIT - <a href="http://datatables.net/license_mit" target="_blank">http://datatables.net/license_mit</a>
  15.  */
  16.  
  17. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  18.  * Easy set variables
  19.  */
  20.  
  21. // DB table to use
  22. $table = 'datatables_demo';
  23.  
  24. // Table's primary key
  25. $primaryKey = 'id';
  26.  
  27. // Array of database columns which should be read and sent back to DataTables.
  28. // The `db` parameter represents the column name in the database, while the `dt`
  29. // parameter represents the DataTables column identifier. In this case object
  30. // parameter names
  31. $columns = array(
  32. array( 'db' => 'first_name', 'dt' => 'first_name' ),
  33. array( 'db' => 'last_name', 'dt' => 'last_name' ),
  34. array( 'db' => 'position', 'dt' => 'position' ),
  35. array( 'db' => 'office', 'dt' => 'office' ),
  36. 'db' => 'start_date',
  37. 'dt' => 'start_date',
  38. 'formatter' => function( $d, $row ) {
  39. return date( 'jS M y', strtotime($d));
  40. }
  41. ),
  42. 'db' => 'salary',
  43. 'dt' => 'salary',
  44. 'formatter' => function( $d, $row ) {
  45. return '$'.number_format($d);
  46. }
  47. )
  48. );
  49.  
  50. // SQL server connection information
  51. $sql_details = array(
  52. 'user' => '',
  53. 'pass' => '',
  54. 'db' => '',
  55. 'host' => ''
  56. );
  57.  
  58.  
  59. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  60.  * If you just want to use the basic configuration for DataTables with PHP
  61.  * server-side, there is no need to edit below this line.
  62.  */
  63.  
  64. require( 'ssp.class.php' );
  65.  
  66. echo json_encode(
  67. SSP::simple( $_POST, $sql_details, $table, $primaryKey, $columns )
  68. );
Go to the top of the page
+Quote Post
nospor
post
Post #12





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




jak sie upierasz to mozesz korzystac z ich klasy SSP, ale mozesz rownie dobrze miec swoj skrypt, ktory zwraca dane w ich formacie. Co ci latwiej
Go to the top of the page
+Quote Post
slawek19926
post
Post #13





Grupa: Zarejestrowani
Postów: 33
Pomógł: 0
Dołączył: 29.07.2016

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


Działa (IMG:style_emoticons/default/smile.gif)
Teraz pytanie jak za pomocą tego mam wykonać działania matematyczne, dodać input, oraz button?
Go to the top of the page
+Quote Post
nospor
post
Post #14





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




A konkretnie o co ci chodzi?
Go to the top of the page
+Quote Post
slawek19926
post
Post #15





Grupa: Zarejestrowani
Postów: 33
Pomógł: 0
Dołączył: 29.07.2016

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


Dokładniej o wyliczanie kwot brutto i po rabacie.

Jak też mam poprawić sortowanie tabeli bo nie działa, wyszukiwanie też nie, oraz pokazuje się komunikat "invalid JSON response" od 14 strony w zwyż.
Go to the top of the page
+Quote Post
nospor
post
Post #16





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Cytat
wyszukiwanie też nie, oraz pokazuje się komunikat "invalid JSON response" od 14 strony w zwyż.

Firefox->firebug->consola
i sobie popatrz co dostajesz od serwera
Go to the top of the page
+Quote Post
slawek19926
post
Post #17





Grupa: Zarejestrowani
Postów: 33
Pomógł: 0
Dołączył: 29.07.2016

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


Problem w tym, że nic nie pokazuje :/
Go to the top of the page
+Quote Post
nospor
post
Post #18





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




TO nic dziwnego ze masz invalid json response skoro nic nie wysylasz (IMG:style_emoticons/default/wink.gif)
Go to the top of the page
+Quote Post
slawek19926
post
Post #19





Grupa: Zarejestrowani
Postów: 33
Pomógł: 0
Dołączył: 29.07.2016

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


Tylko, że do 14 strony wszystko działa bez problemu.

edit:

Przy prawidłowej zmianie strony dostaję coś takiego:
  1. {draw: 19, recordsTotal: 12123, recordsFiltered: 12123,}
  2. data
  3. :
  4. [{id: "131", reference: "004-026", nazwa: "ZASUWNICA S-02 7.5", cena: "8.93", rabat: "0.00"},]
  5. draw
  6. :
  7. 19
  8. recordsFiltered
  9. :
  10. 12123
  11. recordsTotal
  12. :
  13. 12123


Ten post edytował slawek19926 22.09.2016, 13:22:01
Go to the top of the page
+Quote Post
viking
post
Post #20





Grupa: Zarejestrowani
Postów: 6 380
Pomógł: 1116
Dołączył: 30.08.2006

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


Sprawdź co wysyłasz i odbierasz. Może po 14 stronach nie masz danych i tego nie obslużyłeś.
Go to the top of the page
+Quote Post

2 Stron V   1 2 >
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 - 12:52