Si se ha hecho el borrado en bbdd simplemente vuelve a llamar la pagina de borrado se cargará con lo que haya en la bbdd....
Junta las dos ultimas paginas que nos muestras (sin el header), pero rodeando de un condicional las primeras lineas de la ultima si no llega nada por post que no haga el update ... y si el resto de la pagina (la segunda que nos muestras).... despues de la seleccion rellamas a la misma pagina, por AJAX, pero con el post lleno asi se ejectura el UPDATE y despues te mostrará los productos que queden...
Se trata de recargar solo el div "response" no recargar todo el index...
Te adjunto las funciones de js que deben substiuir el action del formulario...
Algo asi
Código PHP:
Ver original<?php
include_once 'lib.php';
// Si hay una seleccion modificamos la bbdd
if (isset($_POST['seleccion'])){ foreach ($_POST['seleccion'] as $id){
echo $id."<br>";
}
// Generamos una lista de los ID's (campo value= ..)
//que tenemos en nuestro array.
$lista=implode(',',$_POST['seleccion']); // Y lo aplicamos al SQL correspondiente y ejecutamos la consulta.
mysql_query("UPDATE stock set activo = 0 WHERE id_stock IN(".$lista.")"); }
// Haya o no seleccion mostramos el contenido de stock
$result = mysql_query("SELECT id_stock, codigo, descrip, pre_min, pre_may, disponibles FROM stock where activo = '1'", $conexion);
?>
<form name='borrar'>
<table id="etiquetas" border='1'>
<tr style="background-color: #ffff99">
<th>ID</th>
<th>Codigo</th>
<th style='width: 500px'>Descrip</th>
<th>Prec.Min</th>
<th>Prec.May</th>
<th>Disponibles</th>
<th></th>
</tr>
<?php
$i=0;
?>
<tr>
<td><?php echo $row['id_stock'] ?></td>
<td><?php echo $row['codigo'] ?></td>
<td style='width: 500px'><?php echo $row['descrip'] ?></td>
<td align=right><?php echo "$"; echo $row['pre_min'] ?></td>
<td align=right><?php echo "$"; echo $row['pre_may'] ?></td>
<td align=center><?php echo $row['disponibles'] ?></td>
<td><input name='seleccion[]' type='checkbox' value=<?php echo $row['id_stock']?>></td>
</tr>
<?php
$i++;
}
?>
</table>
<br>
<input type='button' name='submit' value='enviar' onclick='clSdInFrZnPost("response","stock.php",this.form)'>
</form>
Funciones que te serviran para recargar solo el div "response", deberás modificar la primera para que cargue el array de la selección...
Código Javascript
:
Ver originalfunction clSdInFrZnPost(id,url,formulari){
var parametres="";
var j=0;
for (i=0;i<formulari.elements.length;i++){
if (formulari.elements[i].type!="button"){
j++;
if(j!=1)parametres+="&";
if (formulari.elements[i].type=="checkbox"){
if(formulari.elements[i].checked){
parametres+=formulari.elements[i].id+"="+true;
}else{
parametres+=formulari.elements[i].id+"="+false;
}
}else if (formulari.elements[i].type=="radio"){
if(formulari.elements[i].checked){
parametres+=formulari.elements[i].id
+"="+formulari.elements[i].value;
}
}else{
parametres+=formulari.elements[i].id
+"="+formulari.elements[i].value;
}
}
}
//Si descomentas este alert veras que parametros lanzas....
//alert(parametres);
clientSideIncludePost(id, url, parametres)
}
function clientSideIncludePost(id, url, parametres) {
var req = false;
// For Safari, Firefox, and other non-MS browsers
if (window.XMLHttpRequest) {
try {
req = new XMLHttpRequest();
} catch (e) {
req = false;
}
} else if (window.ActiveXObject) {
// For Internet Explorer on Windows
try {
req = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
req = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
req = false;
}
}
}
//req.expires=-1;
var element = document.getElementById(id);
if (!element) {
alert("Bad id " + id +
"passed to clientSideInclude." +
"You need a div or span element " +
"with this id in your page.");
return;
}
if (req) {
// Synchronous request, wait till we have it all
req.open('POST', url, false);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
req.send(parametres);
element.innerHTML = req.responseText;
} else {
element.innerHTML =
"Sorry, your browser does not support " +
"XMLHTTPRequest objects. This page requires " +
"Internet Explorer 5 or better for Windows, " +
"or Firefox for any system, or Safari. Other " +
"compatible browsers may also exist.";
}
}