i have a problem. i have index.php that returns up to 7 rows in a mysql database. each row has a checkbox. what i want to do is when i check 1-2 or more checkboxes, the apropriate rows in the database are deleted. I don't want to do this manualy row by row. I want to be able to delete more than one row at once. I hope u understand my problem. sorrry for bad english
Thx in advance.
index.php
Code: Select all
<?php
// informatii privind conectarea la $db
// selectarea informartiilor
$sql = "SELECT oferta_generala.id_oferta_generala, pc.nume_pc FROM oferta_generala, pc WHERE (oferta_generala.id_pc = pc.id_pc) ORDER BY oferta_generala.data_anunt DESC LIMIT 7";
$result = mysql_query($sql);
print "<form name='stergere' action='results.php' method='post'>";
// determina nr de inregistrari returnate
$number = mysql_num_rows($result);
// Afiseaza informatiile
print "<table cellpadding=2 cellspacing='2'>
<tr>
<TD bgcolor='#669999'> </TD>
<TD bgcolor='#669999' width='100'> <b>pc</b></TD></TR>";
for($i=0; $i<$number; $i++) {
$id_oferta_generala = mysql_result($result, $i, "id_oferta_generala");
$nume_pc = mysql_result($result, $i, "nume_pc");
// alterneaza culoarea la randuri
if ($i%2 == 0) {
print "<tr bgcolor='Gainsboro'>";
} else {
print "<tr>";
}
print "<TD><INPUT TYPE='CHECKBOX' NAME='alege' VALUE='$id_oferta_generala' ALIGN='middle'></TD>
<TD>$nume_pc</TD></tr>";
}
print "</table>";
print "<INPUT TYPE='SUBMIT' value='Delete' align='middle'></form>";
mysql_close();
?>Code: Select all
<?php
// informatii privind conectarea la $db
if (!isset($_POST['alege'])) {
echo "Trebuie sa alegi cel putin o inregistrare";
} else {
foreach ($_POST['alege'] as $id_oferta_generala) {
$sql="DELETE FROM oferta_generala WHERE id_oferta_generala='".$_POST['id_oferta_generala']."'";
mysql_query($sql);
}
}
?>