Pego el codigo.
Este es el index donde tengo el menu y el div contenedor:
Código HTML:
<html> <head> <link rel="stylesheet" type="text/css" media="screen" href="css.css" /> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <style media="all" type="text/css">@import "css.css";</style> <script type="text/javascript"> function getPages(divid,url) { if(divid !="" && url != "") { var ob= AjaxObject(); var unixTimeStamp= fetch_unix_timestamp(); var nocacheurl = url+ "?t=" + unixTimeStamp; ob.onreadystatechange=function() { if(ob.readyState==4) { if(ob.status == 200) { if(ob.responseText != null) { document.getElementById(divid).innerHTML=ob.responseText; }else { alert('There was an error: no data was received'); } }else { alert('Ajax error:' + ob.statusText); } } } ob.open("GET",nocacheurl,true); ob.send(null); }else{ alert('Se te a olvidado colocar el id del DIV o el URL en el href del achor tag, en el evento de onClick '); } } function fetch_unix_timestamp() { return parseInt(new Date().getTime().toString().substring(0, 10)) } function AjaxObject() { var xmlHttp; try{ return xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari } catch (e){ try{ return xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer } catch (e){ try{ return xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ alert("Sorry AJAX is not supported by your browser."); return false; } } } } </script> </head> <body> <div class="principal" style="background-color: #e0e0e0;"> <div id="menu" class="menu"> <ul> <li><a id="current" href="stock.php" onClick="getPages('response',this); return false" >HOME</a> </li> <li><a href="borrar.php" onClick="getPages('response',this); return false" >Borrar</a> </li> </ul> </div> <table cellpadding="0" cellspacing="0" style="margin-top: 20px" > <tr> <td> <div id="response" style="height: 500px"> <?php include ("stock.php"); ?> </div> </td> </tr> </table> </div> </body> </html>
Código HTML:
<?php include_once 'lib.php'; $conexion= mysql_connect($dbhost, $dbuser, $dbpassword); mysql_select_db($database, $conexion); $result = mysql_query("SELECT id_stock, codigo, descrip, pre_min, pre_may, disponibles FROM stock where activo = '1'", $conexion); ?> <form name='borrar' method='post' action='borrar_prod.php'> <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; while($row = mysql_fetch_array($result)){ ?> <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='submit' name='submit' value='enviar'> </form>
Código PHP:
<?php
require_once 'lib.php';
foreach ($_POST['seleccion'] as $id){
echo $id."<br>";
}
$conexion= mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($database, $conexion);
// 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.")");
header("Location: index.html");
?>