Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

2 Stron V  < 1 2  
Reply to this topicStart new topic
> Checkbox i suma wartości checkboxa, php + mysql
viking
post 20.09.2017, 12:29:30
Post #21





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


W pliku php var_dump($_POST); na samym początku. W konsoli przeglądarki, zakładka sieć, kliknij na żądanie i sprawdź co wysyłasz i odbierasz. Bez tego ani rusz w pracy z ajax.


--------------------
Go to the top of the page
+Quote Post
hunter777
post 20.09.2017, 12:54:10
Post #22





Grupa: Zarejestrowani
Postów: 40
Pomógł: 0
Dołączył: 8.02.2017

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


genialne narzędzie - dziękuję! - namierzyłem wszystkie błędy i wszytko działa!

teraz mam pytanie pisząc ten system i ucząc się przy tym zrobiłem podział na admina i usera i po zalogowaniu user otwiera plik index.php z głównego katalogu a admin index.php z katalogu admin lecz jeśli wpiszę w przeglądarce localhost/admin/index.php a jestem zalogowany jako user to i tak pozwoli mi zobaczyć menu przeznaczone dla admina, czegoś brakuje...
Go to the top of the page
+Quote Post
viking
post 20.09.2017, 12:58:48
Post #23





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


Na początku powinieneś sprawdzić grupę / użytkownika i odmówić dostępu. Twoje zapytania są podatne na sql injection. Poczytaj o bindowaniu parametrów. Dodatkowo jeżeli pole rozliczenia jest int to samo 0 bez ''.

Ten post edytował viking 20.09.2017, 13:00:10


--------------------
Go to the top of the page
+Quote Post
hunter777
post 21.09.2017, 12:46:06
Post #24





Grupa: Zarejestrowani
Postów: 40
Pomógł: 0
Dołączył: 8.02.2017

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


poczytam o sql injection dziękuję za sugestie - sprawdzę także kwestie loginów ale chciałem dokończyć na teraz listę z checkbox'ami, w/g ostatnich skryptów zmienia mi flagę, sumuje pola ale chciałem móc jeszcze zaznaczyć wszystkie checbox'y jednym przyciskiem i zrobiłem to za pomocą skryptu:

  1. <script>
  2.  
  3. //select all checkboxes
  4. $("#select_all").change(function(){ //"select all" change
  5. var status = this.checked; // "select all" checked status
  6. $('.check_list').each(function(){ //iterate all listed checkbox items
  7. this.checked = status; //change ".checkbox" checked status
  8. });
  9. });
  10.  
  11. $('.check_list').change(function(){ //".checkbox" change
  12. //uncheck "select all", if one of the listed checkbox item is unchecked
  13. if(this.checked == false){ //if this item is unchecked
  14. $("#select_all")[0].checked = false; //change "select all" checked status to false
  15. }
  16.  
  17. //check "select all" if all checkbox items are checked
  18. if ($('.check_list:checked').length == $('.check_list').length ){
  19. $("#select_all")[0].checked = true; //change "select all" checked status to true
  20. }
  21. });
  22.  
  23. </script>


wywołanie html

  1. <th><input type="checkbox" class="check_list" id="select_all"/> Zaznacz wszystkie </th>


ale pojawiają się dwie kwestie:

1) zaznacza mi wszystko po kliknięciu ale nie ma sumy tzn jak klikam po kolei w checkbox'y to sumuje wiersze a zaznaczenie przez ten skrypt powoduje tylko zaznaczenie checkbox'ow sumy juz niestety nie wiem czemu nie robi ponieważ flagę zmienia na raz wszystkim bez problemu

2) czy mógłby przy ładowaniu witryny od razu mieć zaznaczone wszystkie checbox'y i robić sumę?


a tu jeszcze ponawiam skrypt sumujący:

  1. <script>
  2. $(document).ready(function(){
  3. update();
  4. });
  5. $('input[type=checkbox]').click(function(){
  6. update();
  7. })
  8. function update(){
  9. var sum = 0;
  10. var sum_n = 0;
  11.  
  12. $('.check_list').each(function () {
  13. if (this.checked) {
  14. sum += Number($(this).attr("val"));
  15. sum_n += Number($(this).attr("val2"));
  16.  
  17.  
  18. }
  19. });
  20. $("#sum_b").html(sum);
  21. $("#sum_n").html(sum_n);
  22.  
  23.  
  24. var checkCount = $(".check_list:checked").length;
  25. $("#avg").html(parseFloat(sum/checkCount).toFixed(2)); }
  26. </script>
  27.  


Ten post edytował hunter777 21.09.2017, 12:53:56
Go to the top of the page
+Quote Post
nospor
post 21.09.2017, 13:10:20
Post #25





Grupa: Moderatorzy
Postów: 36 447
Pomógł: 6292
Dołączył: 27.12.2004




No naprawde moglbys postarac sie zrozumiec te pare linijek kodu co masz...
Toc sumowanie robi funkcja update(). Teraz odpalasz ja za kazdym razem jak klikniesz na jakis checkbox. A jak klikasz "zaznacz wszystkie" to juz jej nie odpalasz i wielce zdziwiony ze nie sumuje... Odpal funkcje update() i tam i bedzie ci sumowac


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
hunter777
post 22.09.2017, 09:48:34
Post #26





Grupa: Zarejestrowani
Postów: 40
Pomógł: 0
Dołączył: 8.02.2017

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


dzięki za pomoc, brzmi to logicznie ale pomimo iż zrobię funkcję update w zaznaczaniu lub nawet wrzucę to funkcji update sumy nie sumuje poprzez zaznaczenie wszystkich, oczywiście analizuję te pare linijek kodu, tzn staram się to robić...

  1. <script>
  2. $(document).ready(function(){
  3. update();
  4. });
  5. $('input[type=checkbox]').click(function(){
  6. update();
  7. })
  8. function update(){
  9.  
  10. $("#select_all").change(function(){ //"select all" change
  11. var status = this.checked; // "select all" checked status
  12. $('.check_list').each(function(){ //iterate all listed checkbox items
  13. this.checked = status; //change ".checkbox" checked status
  14. });
  15. });
  16.  
  17. $('.check_list').change(function(){ //".checkbox" change
  18. //uncheck "select all", if one of the listed checkbox item is unchecked
  19. if(this.checked == false){ //if this item is unchecked
  20. $("#select_all")[0].checked = false; //change "select all" checked status to false
  21. }
  22.  
  23. //check "select all" if all checkbox items are checked
  24. if ($('.check_list:checked').length == $('.check_list').length ){
  25. $("#select_all")[0].checked = true; //change "select all" checked status to true
  26. }
  27. });
  28. var sum = 0;
  29. var sum_n = 0;
  30.  
  31. $('.check_list').each(function () {
  32. if (this.checked) {
  33. sum += Number($(this).attr("val"));
  34. sum_n += Number($(this).attr("val2"));
  35.  
  36.  
  37. }
  38. });
  39. $("#sum_b").html(sum);
  40. $("#sum_n").html(sum_n);
  41.  
  42.  
  43. var checkCount = $(".checkbox:checked").length;
  44. $("#avg").html(parseFloat(sum/checkCount).toFixed(2)); }
  45. </script>
Go to the top of the page
+Quote Post
nospor
post 22.09.2017, 18:22:08
Post #27





Grupa: Moderatorzy
Postów: 36 447
Pomógł: 6292
Dołączył: 27.12.2004




Pewnie slepne, ale nie widze bys dodal update() do klikniecia na "zaznacz wszystkie"... Mozesz mnie oswiecic i wskazac palcem gdzie to dodales dla "zaznacz wszystkie"?


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
hunter777
post 25.09.2017, 11:12:01
Post #28





Grupa: Zarejestrowani
Postów: 40
Pomógł: 0
Dołączył: 8.02.2017

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


nie... to ja głupieje raczej niż Ty ślepniesz...

myślałem, że to update wystarczy

  1. function update(){
  2.  
  3. $("#select_all").change(function(){ //"select all" change
  4. var status = this.checked; // "select all" checked status
  5. $('.check_list').each(function(){ //iterate all listed checkbox items
  6. this.checked = status; //change ".checkbox" checked status
  7. });
  8. });


ale teraz zmieniłem na

  1. function update(){
  2.  
  3. $("#select_all").change(function update(){ //"select all" change
  4. var status = this.checked; // "select all" checked status
  5. $('.check_list').each(function update(){ //iterate all listed checkbox items
  6. this.checked = status; //change ".checkbox" checked status
  7. });
  8. });

i także nie sumuje... hmm... szukam dobrego kursu jQuery! smile.gif, zamówiłem także książkę do algorytmów...
Go to the top of the page
+Quote Post
nospor
post 25.09.2017, 11:18:00
Post #29





Grupa: Moderatorzy
Postów: 36 447
Pomógł: 6292
Dołączył: 27.12.2004




wake up exclamation.gif! wink.gif

Miales do kodu zaznacz wszystkie dodac wywolanie update a nie na odwrot....


Kod
$("#select_all").change(function(){  //"select all" change
    var status = this.checked; // "select all" checked status
    $('.check_list').each(function(){ //iterate all listed checkbox items
        this.checked = status; //change ".checkbox" checked status
    });

  // exclamation.gif!!!O TO MASZ DODAC!!!!!!
update();
});


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
viking
post 29.09.2017, 09:37:15
Post #30





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


Musisz ustawić odpowiednie kodowanie przez nagłówki (header) oraz http://php.net/manual/en/mysqli.character-set-name.php


--------------------
Go to the top of the page
+Quote Post
hunter777
post 2.10.2017, 10:52:45
Post #31





Grupa: Zarejestrowani
Postów: 40
Pomógł: 0
Dołączył: 8.02.2017

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


a gdzie szukać pomocy/przykładów zapytań sql/php - jak połaczyc tabele klient z faktura by to dobrze działało?
Go to the top of the page
+Quote Post
viking
post 2.10.2017, 10:54:58
Post #32





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


https://www.codeproject.com/Articles/33052/...on-of-SQL-Joins


--------------------
Go to the top of the page
+Quote Post

2 Stron V  < 1 2
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: 19.04.2024 - 21:15