Ver Mensaje Individual
  #7 (permalink)  
Antiguo 05/12/2008, 08:43
sergiop21
 
Fecha de Ingreso: diciembre-2008
Mensajes: 805
Antigüedad: 15 años, 5 meses
Puntos: 20
Respuesta: Eliminar registro con php con checkbox

te explico ; y luego te paso el codigo, si.

primero hago una consulta para que me traiga el cliente, luego al lado de cada registro me pone un checkbox, para que cuando quiera eliminar algun registro lo marque con la tilde y luego hacer click en eliminar y borrarlo, es un tipo hotmail.
a continuacion el codigo
gracias por ayudarme.
consulta_cliente.php // nombre de archivo

<html>
<head>
<script>
<?php
require("Librerias/conn.php");
?>
var aBorrar = new Array();
function marcar()
{
var fila, ivalor;
var fila = event.srcElement.parentElement.parentElement.rowIn dex;
var iform;
iform = document.all.tlbnroins.rows(fila).cells(0).innerTe xt;
if (event.srcElement.checked == true){
i = aBorrar.length
aBorrar[i] = iform
//alert (iform);
}
else{
for(i=0; i < aBorrar.length - 1; i++){
if (aBorrar[i] == iform){
aBorrar[i] = aBorrar[aBorrar.length - 1];
i = aBorrar.length;
;}
}
aBorrar.length --;
}
}
function eliminarmv01()
{
//alert ("hola");
var borrar;
if (eval(aBorrar.length)<1 )
{
alert("Debe seleccionar el/los clientes a eliminar.");
return;
}
else
{
borrar= aBorrar[i];
header ("location:eliminar_cliente?borrar = borrar");
}
/*
for (i=0; i < aBorrar.length; i++)
{
if (i == (aBorrar.length - 1))
cadena = cadena + aBorrar[i];
alert (cadena);

}

/*
else
{
cadena = cadena + aBorrar[i] + ",";

}
}

}

/*
//alert(valor1);
//alert(valor2);
//alert(valor3);
//jsrsExecute("../Librerias/rs/procesos.php", eliminarmv01resultado, "eliminarmv01serv",Array(cadena));
/*jsrsExecute("procesos.php", mayorque_resultado, "mayor_que", Array( valor1, valor2) );*/

}

</script>
</head>
<body >
<table border="0" width="50%" >
<tr>
<td align="center"><h1>Consulta de Cliente</h1></td><hr>
</tr>
<tr>
<td colspan="2"><hr width="100%"></td>
</tr>
</table>
<table name="Consul" id="consul" align="center" border="1" width="95%" >
<tr>
<td width="10%" align="center"><b><i>Nº de Cliente</i></b></td>

<td width="10%" align="center"><b><i>Apellido</i></b></td>

<td width="10%" align="center"><b><i>Nombre</i></b></td>

<td width="15%" align="center"><b><i>Domicilio</i></b></td>

<td width="8%" align="center"><b><i>Fecha de Nacimiento</i></b></td>

<td width="8%" align="center"><b><i>Telefono</i></b></td>

<td width="8%" align="center"><b><i>Celular</i></b></td>

<td width="6%" align="center"><b><i>Eliminar</i></b></td>
</tr>
</table>



<?php
//require("Librerias/conn.php");

$codni = $_REQUEST["codni"];
$coape = $_REQUEST["coape"];
$codom = $_REQUEST["codom"];

$sql = "select * from clientes where 1=1 ";
if ($codni != "")
{
$sql .= "and dni ='" . trim($codni) . "'";
}

if ($coape != "")
{
$sql .= "and apellido like '" . trim($coape) . "%'";
}
if ($codom != "")
{
$sql .= "and domicilio like '" . trim ($codom) . "%'";
}



//echo $sql;
//die;
$Conn = ConectarBD();
$result = EjecutarBD($Conn, $sql);

$fdev= pg_num_rows($result);
$count = "select count (idclientes) from clientes";
$count = 0;


?>
<?php

while ($row = pg_fetch_row($result)) {
$count = $count + 1;
?>

<table id="tlbnroins" align="center" border="1" width="95%" name = "tlbnroins" >

<tr>
<td width="10%"><?php echo $row[0]?></td>
<td width="10%"><?php echo $row[1]?></td>
<td width="10%"><?php echo $row[2]?></td>
<td width="15%"> <?php echo $row[3]?></td>
<td width="8%"><?php echo $row[14]?></td>
<td width="8%"><?php echo $row[4]?></td>
<td width="8%"><?php echo $row[5]?></td>
<td width="6%" align="center"><input type="checkbox" name="checked" onClick="marcar()" ></td>
</tr>
</table >

<?php
}
?>


<tr>
<td><b><h3><?php echo (" Se han encontrado '$count' Clientes")?></h3></b></td>
</tr>


<table width="35%" align="center" style="position:relative;top:auto" >
<tr>
<td align="center"><a href="consultar.html" ><input type="button" name="Consultar" value="Consultar" ></a></td>
<td align="center"><input type="button" name="eliminar" value="Eliminar" onClick="eliminarmv01()" ></td>
<td align="center"><a href="principal.html"><input type="button" name="Cancelar" value="Cancelar"></a></td>
</tr>

</table>
<?php


if (isset($Conn)) {
DesconectarBD($Conn);
}
?>
</body>

</html>