este es mi codigo para eliminar uno o varios registros en el cual pagino y elimino
Código PHP:
<body bgcolor="#2C89AD">
<table width="792" height="38" border="0">
<!--DWLayoutTable-->
<tr>
<td width="786" height="34" valign="top" bgcolor=eec236> <p align="center"><font color="#000000" size="5" ><strong>Eliminar</strong></font></td>
</tr>
</table>
<?php
include("conex.php");
$link=Conectarse();
$result=mysql_query("select * from Equipos",$link);
$base="Test";
$link=mysql_connect("localhost","root");
mysql_select_db($base,$link);
if (!isset($pg))
$pg = 0; // $pg es la pagina actual
$cantidad=10; // cantidad de resultados por página
$inicial = $pg * $cantidad;
$pegar = ("SELECT * FROM Equipos ORDER BY Id_Equipos LIMIT $inicial,$cantidad");
$result = mysql_db_query($base,$pegar) or die (mysql_error());
$contar = ("SELECT * FROM Equipos ORDER BY Id_Equipos");
$contarok= mysql_db_query($base,$contar);
$total_records = mysql_num_rows($contarok);
$pages = intval($total_records / $cantidad);
?>
<tr></tr>
<td width="800" height="28" valign="top"> </td>
</tr>
<tr>
<tr>
<tr>
</tr></tr></tr>
<TABLE width="797" height="54" BORDER=1 CELLPADDING=1 CELLSPACING=1>
<!--DWLayoutTable-->
<TR>
<td width="110" height="23"> <div align="justify"> <font size="3"><strong>ACCIONES </strong></font></div></TD>
<td width="64"> </td>
<td width="25"> </td>
<td width="38"> </td>
<td width="40"> </td>
<td width="46"> </td>
<td width="64"> </td>
<td width="129"> </td>
<td width="88"> </td>
<td width="92"> </td>
<td width="81"> </td>
<TR>
<td height="28"></td>
<TD valign="top"><div align="left"><font size="1"><font size="1"> Id_Equipos</font></font></div></TD>
<TD valign="top"><div align="left"><font size="1"> Tipo</font><font size="2"><strong></strong></font></div>
<TD valign="top"><div align="left"><font size="1"> Marca </font></div>
<TD valign="top"><div align="left"><font size="2"><font size="1"> Modelo</font></font></div>
<TD valign="top"><div align="left"><font size="1"> N_Serie</font><font size="2"><strong></strong></font></div></TD>
<TD valign="top"><div align="justify"><font size="1"> Descripción</font><font size="2"><strong></strong></font></div></TD>
<TD valign="top"><div align="left"><font size="1">Fecha_ Compra</font><font size="2"><strong></strong></font></div></TD>
<TD valign="top"><div align="left"><font size="1"> N_Factura</font><font size="2"></font></div></TD>
<TD valign="top"><div align="left"><font size="1"> Rut_ Proveedor</font></div></TD>
<TD valign="top"><div align="left"><font size="1"> Rut_Asignado</font></div></TD>
</TR>
<?php
echo("<form name='form1' method='post' action='BorraMultiple.php'>");
echo("<input name='submit' type='submit' value='Borrar Seleccionado'>");
while($row = mysql_fetch_array($result)) {
echo ("<tr><td><input type='checkbox' name='Id_Equipos[$Id_equipos]'><a onclick='confirmDel(); 'href=\"BorradoSql.php?Id_Equipos=".$row["Id_Equipos"]."\">Eliminar</a>
</td><td>".$row["Id_Equipos"]."</td><td>".$row["Tipo"]."</td><td>".$row["Marca"]."</td>
<td>".$row["Modelo"]."</td><td>".$row["N_Serie"]."</td><td>".$row["Descripcion"]."</td>
<td>".$row["Fecha_Compra"]."</td><td>".$row["N_Factura"]."</td><td>".$row["Rut_Proveedor"]."</td>
<td>".$row["Rut_Asignado"]."</td></tr>");
}
echo("</form>");
mysql_free_result($result);
mysql_close($link);
echo ("<p class=fonty center>");
if ($pg != 0) {
$url = $pg - 1;
echo ("<a href='$PHP_SELF?pg=".$url."'>«Anterior</a>");
}
else {
echo (" ");
}
for ($i = 0; $i <= $pages; $i++) {
if ($i == $pg) {
if ($i == "0") {
echo ("<b> 1 </b>");
}
else {
$i = $i+1;
echo ("<b> ".$i." </b>");
}
}
else {
if ($i == "0") {
echo ("<a href='$PHP_SELF?pg=".$i."'>1</a> ");
}
else {
echo ("<a href='$PHP_SELF?pg=".$i."'>");
$i = $i+1;
echo (" ".$i." </a>");
}
}
}
if ($pg < $pages) {
$url = $pg + 1;
echo ("<a href='$PHP_SELF?pg=".$url."'>Siguiente»</a>");
}
else {
echo (" ");
}
echo ("</p>");
?>
</table>
<table width="772" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="125" height="29"></td>
<td width="176"></td>
<td width="51"></td>
<td width="420"></td>
</tr>
<tr>
<td rowspan="2" valign="top"> <form name="form1" method="post" action="BorraMultiple.php">
</form></td>
<td height="16"></td>
<td valign="top"><div align="center"><a href="Equipos.php"><strong><font size="2">
Volver </font></strong></a></div></td>
<td></td>
</tr>
<tr>
<td height="4"></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="46"> </td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
Código PHP:
//haca es donde llamo a BorraMultiple.php
<?php
include("conex.php");
$link=Conectarse();
$result=mysql_query("select * from Equipos",$link);
// Generamos una lista de los ID's (campo value= ..) que tenemos en nuestro array.
if(count($_POST['Id_Equipos']) > 1) {
$lista = implode(',', $_POST['Id_Equipos']);
}
else {
$lista =($_POST['Id_Equipos']);
}
// Y lo aplicamos al SQL correspondiente y ejecutamos la consulta.
mysql_query("DELETE * FROM Equipos WHERE Id_Equipos IN(".$lista.")",$link);
header('Location: Equipos.php');
mysql_free_result($result);
mysql_close($link);
?>
Cita:
Iniciado por Cluster Indica el código completo que te quedó despues de todas las modificaciones. (usa el botón "PHP" para que el código salga coloreado .. no uses colores própios que no se vé bien ...). Separa y nombra cada uno de los scripts que el código indiques.
Un saludo,