Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Checkbox - przesyłanie danych
qubec26
post
Post #1





Grupa: Zarejestrowani
Postów: 39
Pomógł: 0
Dołączył: 25.06.2008

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


Witam.

Mam kod php, który wyświetla mi wszystkie rekordy z tabeli.
Jest tam dużo kolumn, ale najważniejsze to id i CB(checkbox).
Użytkownik powinien zaznaczyć kilka checkboxów i wcisnąć przycisk i przechodzi do innego pliku, gdzie wyświetla już tylko te wiersze, których checkboxy były zaznaczone w poprzednim pliku.

source.php
  1. <?php
  2. include ('connect.php');
  3. ?>
  4. <form method="post">
  5. <td><input type="button" onClick="document.location='wynik.php'" value="wynik"></td>
  6. </form>
  7. <?php
  8. include('query.php');
  9. $result = mssql_query($query20);
  10. echo "<table cellpadding=\"2\" border=1>";
  11. echo "<tr>";
  12. echo "<th><strong>ID</strong></th>";
  13. echo "<th><strong>CB</strong></th>";
  14. echo "</tr>";
  15. while($r = mssql_fetch_assoc($result)) {
  16. echo "<tr>";
  17. echo "<td>".$r['ID']."</td>";
  18. echo "<td><center><form action='' method='POST'><input type='checkbox' name='data[]' value=".$r['ID']."></form></center></td>";
  19. echo "</tr>";
  20. echo "</table>";
  21. }
  22. mssql_close($dbhandle);


I w pliku wynik.php chciałbym wyświetlić dane.

Jak przesłać dane tych checkboxów do pliku wynik.php?
Tych checkboxów może być nawet powyżej 100.
Go to the top of the page
+Quote Post
nospor
post
Post #2





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




checkboxy mają byc w jednym formularzu a nie 100 checkbox i 100 formularzy (IMG:style_emoticons/default/winksmiley.jpg)
Go to the top of the page
+Quote Post
qubec26
post
Post #3





Grupa: Zarejestrowani
Postów: 39
Pomógł: 0
Dołączył: 25.06.2008

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


Ok. A teraz?

  1. <?php
  2. include ('connect.php');
  3. ?>
  4. <form action='' method='POST'>
  5. <td><input type="button" onClick="document.location='wynik.php'" value="wynik"></td>
  6. <?php
  7. include('query.php');
  8. $result = mssql_query($query20);
  9. echo "<table cellpadding=\"2\" border=1>";
  10. echo "<tr>";
  11. echo "<th><strong>ID</strong></th>";
  12. echo "<th><strong>CB</strong></th>";
  13. echo "</tr>";
  14. while($r = mssql_fetch_assoc($result)) {
  15. echo "<tr>";
  16. echo "<td>".$r['ID']."</td>";
  17. echo "<td><center><input type='checkbox' name='data[]' value=".$r['ID']."></center></td>";
  18. echo "</tr>";
  19. echo "</table>";
  20. }
  21. </form>
  22. mssql_close($dbhandle);
  23. ?>
  24.  
  25.  
Go to the top of the page
+Quote Post
nospor
post
Post #4





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




No teraz powinno byc ok.
Jak te dane odbierasz?
Go to the top of the page
+Quote Post
qubec26
post
Post #5





Grupa: Zarejestrowani
Postów: 39
Pomógł: 0
Dołączył: 25.06.2008

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


Na razie staram się sprawdzić czy w ogóle się coś przekazuje.Mam taki plik:
  1. <?php
  2. require ('sess.php');
  3. // session_start($_GET['id']);
  4. include ('connect.php');
  5. include ('query.php');
  6.  
  7. echo "Dane: ".$_POST;
  8.  
  9. mssql_close($dbhandle);
  10.  
  11. ?>

Go to the top of the page
+Quote Post
nospor
post
Post #6





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




ech.... momentami już brak sił. wszyscy te same bledy robicie.
  1. echo "Dane: ";
  2. print_r($_POST);


ps: przenosze
Go to the top of the page
+Quote Post
qubec26
post
Post #7





Grupa: Zarejestrowani
Postów: 39
Pomógł: 0
Dołączył: 25.06.2008

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


W wyniku dostaję:
Dane: Array ( )
Go to the top of the page
+Quote Post
nospor
post
Post #8





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




1) a zaznaczyles jakis checkbox?
2) czemu akcje ustawiasz js'em? Czemu nie zrobisz:
<form action='wynik.php' method='POST'>
?
Go to the top of the page
+Quote Post
qubec26
post
Post #9





Grupa: Zarejestrowani
Postów: 39
Pomógł: 0
Dołączył: 25.06.2008

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


Zrobiłem jak napisałeś:
Dane: Array ( [data] => Array ( [0] => 281 [1] => 265 ) )

Ale jak teraz obliczyć zmienną licznik (czyli ile checkboxów zostało zaznaczonych)?
  1. for($i=0;$i<$licznik;$i++){
  2. echo "Wartość :".$_POST[data][$i];
  3. }


W sumie załatwiłem to tym:
  1. for($i=0;$i<100;$i++){
  2. if($_POST[data][$i]<>''){
  3. echo "Wartość :".$_POST[data][$i];
  4. }
  5. }


Ten post edytował qubec26 6.09.2010, 13:03:10
Go to the top of the page
+Quote Post
nospor
post
Post #10





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




$_POST['data'] zawiera tablice zaznaczonych checkboxów. Operacje na tablicy to juz chyba znasz? A jak nie znasz to w manualu w dziale tablice jest to opisane (IMG:style_emoticons/default/smile.gif)

Cytat
W sumie załatwiłem to tym:
Lepszy bylby foreach (IMG:style_emoticons/default/winksmiley.jpg)
Włacz wyswietlanie wszystkich bledow a czarno na twojej stronie sie zrobi (IMG:style_emoticons/default/smile.gif)
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: 27.09.2025 - 11:20