Forum Moderators: coopster
The PHP manual has a page regarding PHP and HTML [php.net] that describes how to do what you ask. Well, not entirely. It describes how to setup form input items so that they can be looped through on the server-side by PHP in an array variable.
Here is a somewhat relative script that has a code snippet. You can modify the <select> input item to checkbox and play around a bit to get a feel for how it works in PHP.
Welcome to Webmasterworld. That's pretty easy.
let's say each of your records has a unique id right or primary key, lets say that is
"recordid"
when you display those records , you can add a checkbox for each record and assign value=recordid of that record to its checkbox. now when the form is submitted to your action script, you can simply check for all the values of that checkbox and store thenm in a string in comma seperated format right, now you can simply run a query like
DELETE FROM RECORDS WHERE RECORDID IN (1,2,3,4,5)
where 1,2,3,4,5 in the above query came from the recordid s of the records which were "checked".
<edit>
Ah sorry, i didnt know coopster was posting meanwhile, otherwise i would listen to his words more then saying mine ;)
</edit>
I did, however, forget that link with a sample snippet:
[webmasterworld.com...]
I have this form:
<td><form id="form1" name="form1" method="post" action="remover_email.php">
<table width="40%" border="0" align="center" cellpadding="1" cellspacing="1">
<tr class="menu">
<td width="8%"><div align="center"></div></td>
<td width="92%">E-mail</td>
</tr>
<?php
$p = 0;
do {?>
<tr class="camposinsertos">
<td><div align="center">
<input name="email<? echo $p;?>" type="checkbox"
value="<? echo "$row_remover[id]";?>" />
</div></td>
<td><?php echo $row_remover['mail'];?></td>
</tr>
<?php $p++;} while ($row_remover = mysql_fetch_assoc($remover));?>
<tr>
<td><input type="hidden" name="cantidad" value="<? echo $p;?>" />
</td>
</tr>
<tr><td><input type="submit" value="Remover" /></td></tr>
</table>
<table width="40%" border="0" align="center" cellpadding="1" cellspacing="1">
<tr>
<td> </td>
</tr>
<tr class="etiquetas">
<td>
<input type="checkbox" name="marcatodos" onClick="todos()">Marcar todos ¦
<input type="checkbox" name="desmarcatodos" onClick="ninguno()">Desmarcar todos</td>
</tr>
</table>
<p> </p>
</form>
(I want to apologize for spanish words. from guatemala.)
when i submit the form:
<?php require_once('Connections/mercadeo.php');?>
<?
mysql_select_db($database_mercadeo, $mercadeo);
for ($i = 0; $i<=$_POST[cantidad]; $i++){
$nombre = "email".$i;
$sql = "DELETE FROM remover WHERE id = '$_POST[$nombre]'";
$result = mysql_query($sql, $mercadeo);
}
echo "<script language=\"Javascript\">\r\n";
echo "document.location.href='remover2.php';\r\n";
echo "</script>\r\n";
?>