Ver Mensaje Individual
  #1 (permalink)  
Antiguo 17/06/2012, 20:47
subluis13
 
Fecha de Ingreso: mayo-2011
Ubicación: Caracas
Mensajes: 3
Antigüedad: 13 años
Puntos: 0
Unificar resultados iguales de una consulta a mysql desde php

Buenas noches amigos de antemano agradezco cualquier ayuda que puedan brindarme.

Tengo una especie de sistema de administracion con inventario, entrada de articulos y venta de articulos todo funciona de maravilla tanto el ingreso de articulos como la facturacion para las ventas, el detalle es el siguiente necesito saber la cantidad de articulos existente restando los pedidos que se han realizado y mostrar la cantidad real de articulos existentes.

aqui creo la tabla que contiene los articulos que llegan en el contenedor a a la tienda

create table if not exists `contenido`(
`contenedor` varchar(10) null,
`referencia` varchar(10) null,
`nombre` varchar(50) null,
`precioventa` varchar(11) null,
`descripcion` varchar(255) NULL,
`cantidad` bigint(10) null,
index (`contenedor`)
);

y aqui creo la tabla donde van los datos de los pedidos que se han despachado de ese inventario que llego
CREATE TABLE IF NOT EXISTS `pedidos` (
`numpedido` bigint(10) null,
`contenedor` varchar(10) null,
`referencia` varchar(10) null,
`nombre` varchar(50) null,
`precioventa` varchar(11) null,
`descripcion` varchar(255) NULL,
`cantidad` bigint(10) null,
index ( `numpedido` )
);

El problema que tengo es que cuando traigo los resultados por medio de un juego de registros no se como hacer para restarle a "contenido" las cantidades que existan en "pedidos" y asi mostrar los resultados
Tengo un php para mostrar los resultados de el inventario que llego o sea de la tabla "contenido" es el siguiente.
<?php require_once('Connections/localhost.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

$colname_contenido = "-1";
if (isset($_POST['contenedor'])) {
$colname_contenido = $_POST['contenedor'];
}
mysql_select_db($database_localhost, $localhost);
$query_contenido = sprintf("SELECT * FROM contenido WHERE contenedor = %s ORDER BY referencia ASC", GetSQLValueString($colname_contenido, "text"));
$contenido = mysql_query($query_contenido, $localhost) or die(mysql_error());
$row_contenido = mysql_fetch_assoc($contenido);
$totalRows_contenido = mysql_num_rows($contenido);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Administracion</title>
<script language="javascript" src="Scripts/popcalendar.js"></script>
<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
<link href="estiloadministracion.css" rel="stylesheet" type="text/css" />
</head>
<div id="menu">
<ul id="Menu" class="MenuBarHorizontal">
<li><a class="MenuBarItemSubmenu" href="#">
Articulos</a>
<ul>
<li><a href="agregararticulo.php">Agregar nuevo</a></li>
<li><a href="listado.php">Listado</a></li>
<li><a href="actualizararticulo.php">Modificar</a></li>
<li><a href="buscararticulo.php">Buscar Articulo</a></li>
</ul>
</li>
<li><a href="#" class="MenuBarItemSubmenu">Clientes</a>
<ul>
<li><a href="agregarcliente.php">Agregar nuevo</a></li>
<li><a href="modificarcliente.php">Modificar</a></li>
<li><a href="pedidosrealizados.php">Pedidos realizados</a></li>
<li><a href="carteradeclientes.php">Buscar cliente</a></li>
</ul>
</li>
<li><a class="MenuBarItemSubmenu" href="#">Contenedores</a>
<ul>
<li><a href="agregarcontenedor.php">Agregar nuevo</a></li>
<li><a href="agregararticulos.php">Agregar articulos</a></li> <li><a href="vercontenedor.php">Ver contenedor</a></li>
</ul>
</li>
<li><a class="MenuBarItemSubmenu" href="#">Pedidos</a>
<ul>
<li><a href="nuevopedidoppc.php">Nuevo</a></li>
<li><a href="pedidoporfecha.php">Consultar</a></li>
<li><a href="modificarpedido.php">Modificar</a></li>
</ul>
</li>
</ul>
<script type="text/javascript">
var MenuBar1 = new Spry.Widget.MenuBar("Menu", {imgDown:"SpryAssets/SpryMenuBarDownHover.gif", imgRight:"SpryAssets/SpryMenuBarRightHover.gif"});
</script>
</div>
<table width="650" align="center" id="buscarreferencia">
<tr>
<td align="center" valign="middle"><strong>Ingrese el numero de contenedor para ver los articulos que contiene</strong></td>
</tr>
<tr>
<td align="center">
<form id="buscarcontenedor" name="buscarcontenedor" method="post" action="">
<p>
<input name="contenedor" type="text" value="<?php echo $row_contenido['contenedor']; ?>" />
</p>
<input type="submit" name="button" id="button" value="Buscar" />
</p>
</form></td>
</tr>
</table>
<?php do { ?>
<table width="618" border="1" align="center" id="articulo">
<tr>
<td width="150" rowspan="7" align="center" valign="middle"><img src="imagenes/pics/<?php echo $row_contenido['imagen']; ?>" width="130px" height="130px"></a>
</td>
<td width="140" align="left" valign="top">Referencia</td>
<td width="161" align="left" valign="top"><?php echo $row_contenido['referencia']; ?></td>
<td width="139" rowspan="7" align="center" valign="middle"><img src='imagenes/<?php echo $row_contenido['codigoreferencia']; ?>' width='130px' height='130px' /></a>&quot;</a></td>
</tr>
<tr>
<td align="left" valign="top">Nombre</td>
<td align="left"><?php echo $row_contenido['nombre']; ?></td>
</tr>
<tr>
<td align="left" valign="top">Precio Venta</td>
<td align="left"><?php echo $row_contenido['precioventa']; ?></td>
</tr>
<tr>
<td align="left" valign="top">Cantidad</td>
<td align="left"><?php echo $row_contenido['cantidad']; ?></td>
</tr>
<tr>
<td align="left" valign="top">Descripcion</td>
<td height="59" align="left" valign="top"><?php echo $row_contenido['descripcion']; ?></td>
</tr>
<tr>
<td align="left" valign="top">Contenedor #</td>
<td height="28" align="left"><?php echo $row_contenido['contenedor']; ?></td>
</tr>
</table>
<br />
<?php } while ($row_contenido = mysql_fetch_assoc($contenido)); ?>
</body>
</html>
<?php
mysql_free_result($contenido);
?>

la idea seria mostrarlos realizando la resta de la tabla "pedidos",

Pido disculpas si no me explico bien estoy aprendiendo y de verdad estoy posteando por que no he conseguido la manera de formular mi pregunta debido a que es algo muy especifico, incluso el sistema completo lo he desarrollado con la ayuda de sus foros... muchas gracias espero cualquier ayuda que puedan brindarme