Ver Mensaje Individual
  #28 (permalink)  
Antiguo 31/10/2013, 14:12
dieguito12
 
Fecha de Ingreso: agosto-2009
Mensajes: 73
Antigüedad: 14 años, 8 meses
Puntos: 0
Respuesta: Inconveniente con checkbox para obtener datos relacionados

Para pasar los check con la cantidad es:

Código PHP:
<?php
$lines 
file ('./prueba.txt');
    echo 
"<html>
            <head> 
                <meta http-equiv='Content type' content='text/html'; charset='UTF-8'>
            </head>
            <body>
                <h1 align='center'>Ejercicio 3</h1>"
;
                
    echo 
"<center><form method='POST' action='cargar.php'>";
    
    echo 
"<table border='1'>
    <tr>
        <td>ID Producto</td>
        <td>Nombre</td>
        <td>Descripcion</td>
        <td>Precio</td>
        <td>Seleccion</td>
        <td>Cantidad</td>
    </tr>"
;
    
$id_checkbox 0;
    foreach (
$lines as $line)
    {
        
$id_checkbox++;
        
$datos explode("|"$line);
   
    echo 
"<tr>
                <td>$datos[0]</td>
                <td>$datos[1]</td>
                <td>$datos[2]</td>
                <td>$datos[3]</td>
                <td><input type='checkbox' name='seleccion[]' value='"
.$id_checkbox."'></td>
                <td><input type='text' name='cant_$id_checkbox'></td>
        </tr>"
;
    }
    echo 
"</table><br>
            <input name='boton' type='submit' value='Cargar'></center>"
;
    echo 
"<br><center><a href='index.php'>volver</a></center>";
    echo 
"</body></html>";
?>
Para recibir:

Código PHP:
<?php
$cant_carga 
$_POST["cant_$id_checkbox"];

    
print_r($_POST);
    
$seleccion $_POST['seleccion'];
    
$lines file ('./prueba.txt');
    
    if (isset (
$seleccion))
    {
    echo 
"<html>
            <head> 
                <meta http-equiv='Content type' content='text/html'; charset='UTF-8'>
            </head>
            <body>
                <h1 align='center'>Ejercicio 3</h1>"
;    
    echo 
"<table border='1' align='center'>
    <tr>
        <td>ID Producto</td>
        <td>Nombre</td>
        <td>Descripcion</td>
        <td>Precio</td>
        <td>Cantidad</td>
    </tr>"
;
            
$id_checkbox 0;
            foreach(
$lines as $line)
            {    
                
$id_checkbox++;
                
$datos explode("|"$line);
                if( 
in_array($id_checkbox$seleccion ) )
                {
                    echo 
"<tr>
                        <td>$datos[0]</td>
                        <td>$datos[1]</td>
                        <td>$datos[2]</td>
                        <td>$datos[3]</td>
                        <td>"
.$cant_carga." hola</td>
                    </tr>"
;
                }
            }
            echo 
"</table><br>";
    }
    else
    {
        echo 
"No se ha seleccionado ningun elemento";
        
header("Location: tabla.php");
    }
    echo 
"<br><center><a href='index.php'>volver</a></center>";
    echo 
"</body></html>";
?>