Log in

View Full Version : delete multiple registers of MySql DB



pavmoxo
04-13-2006, 04:08 PM
I have this part of a form


<select name="actas2[]" size="5" multiple>
<?
$sql = "select * from actas2 where area_ID = 1 order by year desc, number desc";
$query = query($sql);
$conta = mysql_num_rows($query);
for ($i=0;$i<$conta;$i++)
{
$arr = mysql_fetch_array($query);
?>
<option value="<? echo $arr["acta_ID"]; ?>"><? echo trata_data1($arr["dia"])." -> acta ".$arr["number"]." realizada em ".$arr["day"]." de ".trata_month($arr["month"])." de ".$arr["year"]; ?><? if ($arr['active'] == 'n') { ?> - Inactivo<? }?></option>
<?
}
?>

</select>


And the php:


/* APAGAR */
if(isset($_POST['apagar']))
{
if(!isset($_POST['actas2'])){
$err = 'Não escolheu um registo!';
}
else{
if(is_array($_POST['actas2'])){
$id = implode(',',$_POST['actas2']);
}
else{
$id = $_POST['actas2'];
}
$sql = "delete from actas2 where actas2_ID in (" . $id . ") and area_ID = 1";
$query = query($sql);
if ($query == 1)
{
echo "<script>alert('O documento foi apagada com sucesso.');</script>";
}
else
{
echo "<script>alert('Problemas ao remover o documento.');</script>";
}
}

}


I don´t obtain the result that I want - delete one or more registries

Atolar
04-13-2006, 07:24 PM
Why are you using query($sql) and not mysql_query($sql) ?