Ver Mensaje Individual
  #1 (permalink)  
Antiguo 30/07/2009, 07:58
Avatar de ix0ye
ix0ye
 
Fecha de Ingreso: julio-2009
Ubicación: queretaro
Mensajes: 41
Antigüedad: 14 años, 9 meses
Puntos: 1
Recorrer tres arreglos al mismo tiempo

Hola a todos!

pues la verdad es que soy un novato en esto de php y en este momento me encuentro muy atorado

mi problema es el siguiente:

en la pagina ver_carrito.php hago una consulta a mi bd, lo muestro en una tabla, el problema es que en esa pagina el usuario debe ingresar la cantidad de productos que desea, ademas de poner un comentario del producto o de su pedido.

por lo que creo un arreglo de los valores que necesito es decir

id_producto[] cantidad[] comentario[]

y los mando junto con otros valoes a actualiza_carrito.php

pero . . .

con un foreach puedo recorrer cada arreglo, el punto es que yo necesito recorrer los tres arreglos al mismo tiempo, pues el update de mi bd se basa en esos tres valores

de antemano mil gracias masters!

acodigo de ver_carrito.php
Código PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<html>
<head>
<link rel="shortcut icon" href="leeslab.ico">
<title>
<?php
echo"Carrito de $e ";
?>
</title>
<style type="text/css">
<!--
a {font-family:Arial;font-size:12px;color:#003366;text-decoration:none}

a:visited {font-family:Arial;font-size:12px;color:#003366;text-decoration:none}

a:hover {font-family:Arial;font-size:14px;color:#003366;text-decoration:underline}

.descripcion {font-family:Arial, Helvetica, sans-serif;font-size:11px;color:#000066;}

.titulos {font-family:Arial;font-size:16px;color:#FFFFFF;font-weight:bold;}

.default
{
font-family:Verdana;font-size:12px;color:#BDBDBD
}
-->
</style>
<script language="JavaScript" type="text/javascript">
<!--
  function enviar()
 {
  document.forma.submit();
 } 
//-->
</script>
</head>
<?php
include("funciones.php");
conectar();
if(
verifica_sesion($e,$s))
{
$result=mysql_query("select id_producto,nombre_producto,descripcion,unidad,cantidad from productos left join productos_carrito using (id_producto) where id_carrito='$id_carro'")or die (mysql_error());
$total=mysql_num_rows($result);
if(
$total<=0)
{
 echo
"<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>
<META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=ISO-8859-1'>
<html>
<head>
<title>Untitled</title>
<style type='text/css'>
<!--
.formularios {font-family:Verdana;font-size:20px;color:blue}
a {font-family:Arial;font-size:16px;color:#639EEA;text-decoration:none}
a:visited {font-family:Arial;font-size:16px;color:#639EEA;text-decoration:none}
a:hover {font-family:Arial;font-size:16px;color:##639EEA;text-decoration:underline}
-->
</style>
</head>
<body bgcolor='#639EEA'>
<br><br><br><br>
<table border='1' bgcolor='#FFFFFF' align='center'>
<tr>
<td>
<table summary='' width='400'>
<tr align='center'>
<td><img src='llla.gif' alt='' width='275' height='62'></a></td>
</tr>
<tr align='center'>
<td class='formularios'>No se ha insertado ningun producto</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>"
;
}
else
{
echo
"<body bgcolor='#639EEA'>";

echo
"<form name='forma' method='post' action='actualiza_cantidad.php'>
<table summary='' align='center' width=1000 style='border:1px solid #000000;' border=0>
<tr class='titulos' bgcolor='#000066'>
<td>Nombre</td><td>Descripcion</td><td>Unidad</td><td>Cantidad</td><td>Comentario</td><td>Actualizar cantidades</td>
</tr><tr><td><input type='text' name='id_carro' value='$id_carro' /></td></tr>"
;
while(
$row=mysql_fetch_array($result))
{
 
extract($row);
 echo
"<tr  class='descripcion' bgcolor='#CCCCCC'>
 <td>$nombre_producto</td>
 <td>$descripcion</td>
 <td>$unidad</td>
 <td><input type='text' name='$id_producto' value='$cantidad' maxlength='10' size='2'><input type='text' name='id_producto[]' value='$id_producto'</td>
 <td><input type='text' class='default' name='coment[]' value='hola hola hola' maxlength='100' size='60' onfocus='javascript:comentar();' ></form></td>
 <td></td> 
 </tr>"
;
}
echo
"<tr><td><input type='button' value='Enviar' onclick='javascript:enviar();' /></td></tr></table></form>";
echo
"<p align='center'><a href='ver_carrito.php?e=$e&s=$s&id_carro=$id_carro'>Actualiz&aacute;r<img src='actualizar.gif' title='Actualizar' border=0></a></p><br></body>";

}
}
else
{
 
header("location:error.php?tipoerror=2");
 
desconectar();
}
?>
este es el codigo de actualiza_carrito.php
Código PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<?php
include("funciones.php");
conectar();
echo
"hola";
/*
echo"<table border><tr><th>Id_producto</th><th>Cantidad</th><th>Comentario</th></tr><tr>";
echo"$cantidad";
foreach($_POST['id_producto'] as $id_producto)

 foreach($_POST['cantidad'] as $cantidad)
 {
  $rs=("update productos_carrito set cantidad='$cantidad' where id_producto='$id_producto' and id_carro='$id_carro'")or die (mysql_error());
    if(mysql_query($rs))
    {
     echo"agragado<br>";     
    }
    else
    {
     echo"maldito error!";
    }
 }
  //$rs=mysql_query("select id_producto,cantidad,comentario from productos_carrito where id_producto='$id_producto' and id_carrito='$id_carro'")or die (mysql_error());
  //$row=mysql_fetch_array($rs);
  //extract($row);
  //print("<td>$id_producto</td><td>$cantidad</td><td>$comentario</td></tr>");  
}
echo"</table>";
*/
//echo"<table><tr><th>Id producto</th><th>Cantidad</th><th>Comentario<th></th></tr><tr><td>";
/* 

echo"</td><td>";
foreach($_POST['cantidad'] as $cantidadd)
{
 echo"$cantidadd<br>";
}
echo"</td><td>";
foreach($_POST['coment'] as $comentario)
{
 echo"$comentario<br>";
}
echo"</td></tr></table>";
*/
?>
</body>
</html>
otra vez gracias!!!