Ver Mensaje Individual
  #5 (permalink)  
Antiguo 26/12/2005, 18:15
Avatar de Watas
Watas
 
Fecha de Ingreso: diciembre-2005
Ubicación: Caracas
Mensajes: 151
Antigüedad: 18 años, 4 meses
Puntos: 0
Código PHP:
<?php  
session_start
(); 
//Iniciamos o retomamos la sesión 
$carro=$_SESSION['carro']; 
//La asignamos a la variable $carro 
?>
<?php  
if($carro){ 
//si el carro no está vacío, mostramos los productos 
?> 
<table width="800" border="0"  bgcolor="#FFFFFF" cellspacing="1" cellpadding="0" align="center"> 
  <tr bgcolor="#333333" class="tit">  
    <td colspan="2" align="center">Cantidades</td>
    <td width="100" align="center">Actualizar</td>
    <td width="115" align="center">Eliminar</td>  
    <td width="100" align="center">Artista</td> 
    <td width="100" align="center">Titulo</td> 
    <td width="100" align="center">Precio</td> 
  </tr> 
  <?php 
  $color
=array("#FFFFFF","#F0F0F0"); 
  
$contador=0
  
//las 2 líneas anteriores sirven para hacer una tabla con colores alternos 
  
$suma=0
  
//antes de recorrer todos los valores de la matriz carro, ponemos a cero la variable $suma, 
  //en la que iremos sumando los subtotales del costo de cada item por la cantidad de unidades que se especifiquen 
   
foreach($carro as $k => $v){ 
   
//recorremos la matriz que tiene todos los valores del carro, calculamos el subtotal y el total 
   
$total=$v['cantidad']*$v['Precio']; 
   
$suma=$suma+$total
   
$contador++;//este es el contador que usamos para los colores alternos 
    
?> 

  <form name="a<?php echo $v['identificador'?>" method="post" action="agregacar.php?<?php echo SID ?>" id="a<?php echo $v['identificador'?>"> 
     <tr bgcolor="<?php echo $color[$contador%2]; ?>" class='prod'>        
     <td width="20" align="center"><?php echo $v['cantidad'?></td>
      <td width="13" align="center">       
       <input name="cantidad" style="text-align:right" type="text" id="cantidad" value="<?php echo $v['cantidad'?>" size="2"> 
       <input name="id" type="hidden" id="id" value="<?php echo $v['id'?>">  </td>  
        <td align="center">  
        <input name="imageField" type="image" src="actualizar.gif" width="20" height="20" border="0"></td> 
             <td align="center">
      <a href="borracar.php?<?php echo SID ?>&id=<?php echo $row['Id']; ?><?php echo $v['Id'?>"><img src="trash.gif" width="12" height="14" border="0" title="Eliminar del Carrito"></a>

      <td><?php echo $v['Artista'?></td> 
      <td><?php echo $v['Titulo'?></td> 
      <td><?php echo $v['Precio'?></td> 
     </td> 
     
  </tr></form> 
  <?php  
  
//por cada item creamos un formulario que submite a agregar producto y un link que permite eliminarlos 
  
}?> 
 </table>
 <table width="800" border="0"  bgcolor="#FFFFFF" cellspacing="0" cellpadding="0" align="center"> 
  <tr bgcolor="#333333" class="tit">  
    <td width="50"></td> 
    <td width="50"></td> 
    <td width="50"></td> 
    <td colspan="2" align="center"></td> 
    <td width="100" align="center"></td> 
    <td width="159" align="center"></td> 
  </tr> 
 </table>
 <table  align="center" width="800" border="0" bgcolor="#FFFFFF">
<tr bgcolor="#FFFFFF">
<div align="left"><span class="prod2">Total de Artículos: <?php echo count($carro); 
//el total de items va a ser igual a la cantidad de elementos que tenga la matriz $carro, valor que obtenemos con la 
//función count o con sizeof 
?></span>  
<div align="right"><span class="prod2">Total: Bs.<?php echo number_format($suma,2); 
//mostramos el total de la variable $suma formateándola a 2 decimales 
 
?></span>  
</div> </div>
</br>

<div align="right"><span class="prod2">Agregar más Artículos</span>  
  <a href="buscar.html<?php echo SID;?>"><img src="continuar.gif" width="13" height="13" border="0"></a>  
</div> 

<?php }else{ ?> 
<p align="center"> <span class="prod2">No hay Artículos en su Carrito</span> <a href="buscar.html<?php echo SID;?>"><img src="continuar.gif" width="13" height="13" border="0"></a>  
  <?php }?>