Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> przekazywanie checkbxow
szymono
post
Post #1





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 9.02.2004

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


mam taki problem
na jednej stroie tworzy sie lista osob jest to robione petla i wyciagane z bazy danych sql
wyglada to tak
[php:1:9af2f9b989]<?php
$link_id=db_connect();
if(!$link_id) die(sql_error());
$query = "select * from student";
$result = mysql_query($query) or die ("invalid query: " . mysql_error());

echo " <form method="post" action="usunstudenta.php"";


while ($query_data = mysql_fetch_array($result)){
$imie=$query_data['stud_imie'];
$studid = $query_data['studid'];
echo "<tr><td width="2%"><input name="del[]" value="i" type="checkbox" ></td>";
"<input type="hidden">".$studid." ";
echo "<td width="12%">".$studid."</td>";
echo "<td width="10 %">".$query_data['stud_nazwisko']."</td>";
echo "<td width="10 %">".$query_data['nr_indeksu']."</td>";
echo "<td width="10 %">".$query_data['rok_studiow']."</td>";
echo "<td width="10 %">".$query_data['semestr']."</td>";
echo "<td width="5%"><a href="index.php?file=listastudentow.php&action=edytuj&studid=$studid "> wyswietl</a></td></tr>";
}

?>[/php:1:9af2f9b989]

i teraz na dole strony znajduje sie link ktory ma przekazac do tej samej strony tylko te pola przy ktorych zaznaczono checkboxa
link wyglada tak
Kod
<a href="index.php?file=listastudentow.php&action=del&studid=<? $del[studid] ?>">Usun zaznaczonych</a></td>

przy czym del to funkcja ktora ma wyswietlic ta tabelke z osobami przy ktorych zaznaczono checkboxy.
i wszystko sie dzieje na jednej stronie tej listastudentow
ale to nie chce dzialac? czy zle skonstruowalem linka (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif) czy cos innego ?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
kossa
post
Post #2





Grupa: Zarejestrowani
Postów: 1 165
Pomógł: 9
Dołączył: 9.04.2002
Skąd: Toruń

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


co robi ta funkcja?

Kod
html_header();


zaraz przeanalizuje kod
masz balagan w kodzie - niedomknieta tabela, oj brzydko, brzydko...

Kossa

mam juz, poza balaganem w kodzie bo brzydko piszesz, form zamknales zaraz po pierwszym studencie! przy if ($action...) nie bylo $!, pomiedzy </tr> a nastepnym <tr> wstawiasz <br> ?! i takie tam bledy...

tu masz kod dzialajacy, dostosuj go do swoich potrzeb:

Kod
<table>

<tr><td height="21"  colspan="7" valign="top" id="log">Lista studentow</td></tr>

<tr><td height="21"  colspan="7" valign="top" id="log"><form method="post"  action="index.php?file=istastudentow.php&action=delete"></td></tr>

<tr><td height="21"  colspan="7" valign="top" id="log"><input type="submit" value = "usun zaznaczonych"></td></tr>

</tr>

    <tr>

      <td width="2%" height="26" id="kolor2">zaznacz</td>

      <td width="10%" height="26"  id="kolor2">imie</td>

      <td width="10%" height="26"  id="kolor2">nazwisko</td>

      <td width="8%" height="26"  id="kolor2">nr indeksu</td>

      <td width="5%" height="26"  id="kolor2">rok studiow</td>

      <td width="5%" height="26"  id="kolor2">semestr</td>

      <td width="5%" height="26"  id="kolor2">edytuj</td>    

    </tr>

<?php

global $action;



function PokazStudentow()

{

global $action;

$table = "student";

$query = "select * from $table";

$result = mysql_query($query) or die ("invalid query: " . mysql_error());

    

while ($query_data = mysql_fetch_array($result))

{

    $studid = $query_data["studid"];

    $imie=$query_data['stud_imie'];

    $nazwisko=$query_data['stud_nazwisko'];

    $indeks=$query_data['nr_indeksu'];

    $rok=$query_data['rok_studiow'];

    $semestr=$query_data['semestr'];

echo "<tr><td width="2%"><input type="checkbox" value="$studid" name="del[]"></td>";

echo "<td width="12%">".$imie."</td>";

echo "<td width="10 %">".$nazwisko."</td>";

echo "<td width="10 %">".$indeks."</td>";

echo "<td width="10 %">".$rok."</td>";

echo "<td width="10 %">".$semestr."</td>";

echo "<td width="5%">

<a href="index.php?file=listastudentow.php&action=edytuj&studid=$studid">wyswietl</a></td></tr>";

}



echo "</form></TABLE>";



};



if ($action=="delete")

{

  for ($i=0; $i<count($del); $i++)

  {

    $usun_id = $del[$i];

    $query = "delete from student where id = $usun_id";

    $result = mysql_query ($query);

  }

}



PokazStudentow();



?>


Kossa
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: 16.10.2025 - 16:22