Código PHP:
<?php
session_start();
include('php_conexion.php');
$act="0";
include_once("php_conexion.php");
if(!empty($_GET['del'])){
$id=$_GET['del'];
mysql_query("DELETE FROM carrito WHERE codigo='$id'");
}
if(!$_SESSION['tipo_usu']=='a' or !$_SESSION['tipo_usu']=='ca'){
header('location:index.php');
}
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="utf-8">
<title>Carrito de Compras</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link href="/bootstrap.css" rel="stylesheet">
<style type="text/css">
body {
padding-top: 60px;
padding-bottom: 40px;
}
</style>
<link href="/bootstrap-responsive.css" rel="stylesheet">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="/html5shiv.js"></script>
<![endif]-->
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="/apple-touch-icon-57-precomposed.png">
<link rel="shortcut icon" href="/favicon.png">
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="brand" href="#">Tienda</a>
<div class="nav-collapse collapse">
<ul class="nav">
<li class="active"><a href="index.php">Principal</a></li>
<li><a href="mis_pedidos.php">Mis Pedidos</a></li>
</ul>
</li>
<table width="200" border="2" align="right">
<tr>
<td bgcolor="#FFFFFF"><a href="#" id="drop3" role="button" class="dropdown-toggle" data-toggle="dropdown"><i class="icon-user"></i> Hola! <?php echo $_SESSION['username']; ?> <b class="caret"></b></a>
<ul class="dropdown-menu" role="menu" aria-labelledby="drop3">
<li role="presentation"><a role="menuitem" tabindex="-1" href="cambiar_clave.php" target="admin"><i class="icon-refresh"></i> Cambiar Contraseテアa</a></li>
<li role="presentation" class="divider"></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="php_cerrar.php"><i class="icon-off"></i> Salir</a></li></td>
</tr>
</table>
</div><!--/.nav-collapse -->
</a>
</div>
</div>
</div>
<div class="container">
<div class="hero-unit" align="center">
<p><img src="banner.png" class="img-polaroid"></p>
</div>
<div class="row">
</div>
<div align="center">
<div class="row-fluid">
<div class="span8">
<?php
$pa=mysql_query("SELECT * FROM producto where estado='s'");
while($row=mysql_fetch_array($pa)){
?>
<table class="table table-bordered">
<tr><td>
<div class="row-fluid">
<div class="span4">
<center><strong><?php echo $row['nombre']; ?></strong></center><br>
<img src="<?php echo $row['codigo']; ?>.png" class="img-polaroid">
</div>
<div class="span4"><br><br><br><br>
<strong><?php echo $row['nota']; ?></strong><br><br>
<strong>Valor: </strong>$ <?php echo number_format($row['valor'],2,",","."); ?>
</div>
<div class="span4"><br><br><br><br><br>
<form name="form<?php $row['codigo']; ?>" method="post" action="">
<input type="hidden" name="codigo" value="<?php echo $row['codigo']; ?>">
<button type="submit" name="boton" class="btn btn-primary">
<i class="icon-shopping-cart"></i> <strong>Agregar al Carrito</strong>
</button>
</form>
<div class="span4"><br><br><br><br>
<strong>Existencia: </strong> <?php echo number_format($row['existencia']); ?>
</div>
</div>
</div>
</td></tr>
</table>
<?php } ?>
</div>
<div class="span4">
<?php
if(!empty($_POST['codigo'])){
$codigo=$_POST['codigo'];
$pa=mysql_query("SELECT codigo, cantidad FROM carrito WHERE usu = '" . $_SESSION["username"] . "' AND codigo = '". $codigo . "'");
if($row=mysql_fetch_array($pa)){
$new_cant=$row['cantidad']+1;
mysql_query("UPDATE carrito SET cantidad = '" . $new_cant . "' WHERE usu = '" . $_SESSION["username"] . "' AND codigo = '" . $codigo . "'");
}else{
mysql_query("INSERT INTO carrito (codigo, cantidad, usu) VALUES('" . $codigo . "', '1', '" . $_SESSION["username"] . "')");
}
}
?>
<div id="sidebar"><br><br><br>
<h2 align="center">Mis Pedidos</h2>
<table class="table table-bordered">
<tr>
<td height="153">
<table class="table table-bordered table table-hover">
<?php
$neto=0;$tneto=0;
$pa=mysql_query("SELECT * FROM carrito WHERE usu = '". $_SESSION["username"] ."'");
while($row=mysql_fetch_array($pa)){
$oProducto=new Consultar_Producto($row['codigo']);
$neto=$oProducto->consultar('valor')*$row['cantidad'];
$tneto=$tneto+$neto;
?>
<tr style="font-size:9px">
<td><?php echo $oProducto->consultar('nombre'); ?></td>
<td><?php echo $row['cantidad']; ?></td>
<td>$ <?php echo number_format($neto,2,",","."); ?></td>
<td>
<a href="index.php?del=<?php echo $row['codigo']; ?>" title="Eliminar de la Lista">
<i class="icon-remove"></i>
</a>
</td>
</tr>
<?php }
?>
<td colspan="4" style="font-size:9px"><div align="right">$<?php echo number_format($tneto,2,",","."); ?></div></td>
<?php
$pa=mysql_query("SELECT * FROM carrito WHERE usu = '". $_SESSION["username"] ."'");
if(!$row=mysql_fetch_array($pa)){
?>
<tr><div class="alert alert-success" align="center"><strong>No hay Productos Registrados</strong></div></tr>
<?php } ?>
</table></td>
</tr>
</table>
</div>
</div>
</div>
</div>
<hr>
<footer>
<p>© Venezuela Computer 2014</p>
<p> </p>
</footer>
</div> <!-- /container -->
<script src="/jquery.js"></script>
<script src="/bootstrap-transition.js"></script>
<script src="/bootstrap-alert.js"></script>
<script src="/bootstrap-modal.js"></script>
<script src="/bootstrap-dropdown.js"></script>
<script src="/bootstrap-scrollspy.js"></script>
<script src="/bootstrap-tab.js"></script>
<script src="/bootstrap-tooltip.js"></script>
<script src="/bootstrap-popover.js"></script>
<script src="/bootstrap-button.js"></script>
<script src="/bootstrap-collapse.js"></script>
<script src="/bootstrap-carousel.js"></script>
<script src="/bootstrap-typeahead.js"></script>
<script>
$(function() {
var offset = $("#sidebar").offset();
var topPadding = 15;
$(window).scroll(function() {
if ($("#sidebar").height() < $(window).height() && $(window).scrollTop() > offset.top) { /* LINEA MODIFICADA */
$("#sidebar").stop().animate({
marginTop: $(window).scrollTop() - offset.top + topPadding
});
} else {
$("#sidebar").stop().animate({
marginTop: 0
});
};
});
});
</script>
</body>
</html>