Foros del Web » Programando para Internet » PHP »

restar campos

Estas en el tema de restar campos en el foro de PHP en Foros del Web. Hola buenas estoy haciendo una base de datos que liste las existencias del almacén, tengo 3 campos que son exmprls(ejemplares),rtrr(retirar) y ttl(total) necesito hacer que ...
  #1 (permalink)  
Antiguo 28/04/2008, 01:46
 
Fecha de Ingreso: abril-2008
Mensajes: 70
Antigüedad: 16 años
Puntos: 0
restar campos

Hola buenas estoy haciendo una base de datos que liste las existencias del almacén, tengo 3 campos que son exmprls(ejemplares),rtrr(retirar) y ttl(total) necesito hacer que en el campo retirar al poner una cantidad reste del campo ejemplares las existencias que hay actualizándolas a la nueva cantidad, si no otra opcion es que me lo muestre en el campo total. Al hacerlo de la primera forma me estoy dando cuentra que el campo total sobraria.

Alguien me puede echar una mano?, gracias.

En la misma web tengo un apartado para insertar nuevos registros, para actualizar registros y otro para borrar (pero ese no me chuta)

Os pego el código:

Código PHP:
<?php require_once('Connections/prueba.php'); ?>
<?php
function GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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;
}

$editFormAction $_SERVER['PHP_SELF'];
if (isset(
$_SERVER['QUERY_STRING'])) {
  
$editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']);
}

$editFormAction $_SERVER['PHP_SELF'];
if (isset(
$_SERVER['QUERY_STRING'])) {
  
$editFormAction .= "listadotlf.php" htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset(
$_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  
$updateSQL sprintf("UPDATE existencias SET ano_pblccn=%s, ttlo=%s, isbn=%s, pdf=%s, exmplrs=%s, ttl=%s WHERE id=%s",
                       
GetSQLValueString($_POST['ano_pblccn'], "int"),
                       
GetSQLValueString($_POST['ttlo'], "text"),
                       
GetSQLValueString($_POST['isbn'], "text"),
                       
GetSQLValueString($_POST['pdf'], "text"),
                       
GetSQLValueString($_POST['exmplrs'], "int"),
                       
GetSQLValueString($_POST['ttl'], "int"),
                       
GetSQLValueString($_POST['id'], "int"));

  
mysql_select_db($database_prueba$prueba);
  
$Result1 mysql_query($updateSQL$prueba) or die(mysql_error());

  
$updateGoTo "listadotlf.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$updateGoTo .= (strpos($updateGoTo'?')) ? "&" "?";
    
$updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$updateGoTo));
}

if ((isset(
$_POST["MM_update"])) && ($_POST["MM_update"] == "form2")) {
  
$updateSQL sprintf("UPDATE existencias SET ano_pblccn=%s, ttlo=%s, isbn=%s, pdf=%s, exmplrs=%s, ttl=%s WHERE id=%s",
                       
GetSQLValueString($_POST['ano_pblccn'], "int"),
                       
GetSQLValueString($_POST['ttlo'], "text"),
                       
GetSQLValueString($_POST['isbn'], "text"),
                       
GetSQLValueString($_POST['pdf'], "text"),
                       
GetSQLValueString($_POST['exmplrs'], "int"),
                       
GetSQLValueString($_POST['ttl'], "int"),
                       
GetSQLValueString($_POST['id'], "int"));

  
mysql_select_db($database_prueba$prueba);
  
$Result1 mysql_query($updateSQL$prueba) or die(mysql_error());

  
$updateGoTo "listadotlf.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$updateGoTo .= (strpos($updateGoTo'?')) ? "&" "?";
    
$updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$updateGoTo));
}

mysql_select_db($database_prueba$prueba);
$query_rs_existencias "SELECT existencias.id, existencias.ano_pblccn, existencias.ttlo, existencias.isbn, existencias.pdf, existencias.exmplrs, existencias.ttl, existencias.rtrr FROM existencias ORDER BY existencias.ano_pblccn";
$rs_existencias mysql_query($query_rs_existencias$prueba) or die(mysql_error());
$row_rs_existencias mysql_fetch_assoc($rs_existencias);
$totalRows_rs_existencias mysql_num_rows($rs_existencias);
?>
<html>
<head>
<title>Listado Existencias do almacén</title>
</head>

<body>
<br><br><br><form name="form1" method = "GET" action = "buscador.php">
<strong><center align>Búsqueda na base de datos:</strong>
<input type="text" name="buscar" size="20">
<input type="submit" value="buscar">
</form></center>
<p>&nbsp;</p>
   <p><strong>Insertar Novo rexistro </br>
   
<form method="POST" name="form" action="insertar2.php">
  <table align="">
    <tr valign="baseline">
      <td nowrap align="right">Ano Publicación:</td>
      <td><input type="text" name="ano_pblccn" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Título:</td>
      <td><input type="text" name="ttlo" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Isbn:</td>
      <td><input type="text" name="isbn" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Pdf:</td>
      <td><input type="text" name="pdf" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Exenplares:</td>
      <td><input type="text" name="exmplrs" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">&nbsp;</td>
      <td><input type="submit" name="accion" value="insertar"></td>
    </tr>
  </table>
 
</form>
   </strong></p>
   <?php do { ?>

  <table align=center width="90%" border="1" STYLE="table-layout:fixed">
    <tr> 


      <td align=center width="4%"><font size="2px"><?php echo $row_rs_existencias['ano_pblccn']; ?>  </td>
      <td align=center width="25%"><font size="2px"><?php echo $row_rs_existencias['ttlo']; ?></td>
      <td align=center width="10%"><font size="2px"><?php echo $row_rs_existencias['isbn']; ?></td>
      <td align=center width="3%"><font size="1"><?php echo $row_rs_existencias['pdf']; ?></td>  
      <td align=center width="1%"> <font size="2px"><div align="center"><a href="formulario.php?id= <?php echo $row_rs_existencias['id']; ?>"><img src="actualizar.jpg" width="23" height="20" border="0"></a></div></td>
       <td align=center width="1%"> <font size="2px"><div align="center"> <script language="Javascript">
function preguntar(){
eliminar=confirm("¿Desexas eliminar este rexistro?");
if (eliminar)
//Redireccionamos si das a aceptar
window.location.href ="borra.php?id=%d"; //página web a la que te redirecciona si confirmas la eliminación
else
//Y aquí pon cualquier cosa que quieras que salga si le diste al boton de cancelar
alert('Non se ha puido eliminar o rexistro...')
}
</script> 
       <a href="javascript:preguntar()"><img src="papelera.jpg" width="23" height="20" border="0"> </a></div></td>
             <td align=center width="3%"><font size="2px"><?php echo $row_rs_existencias['exmplrs']; ?></td>  
          <td align=center width="1%"><font size="2px"><?php echo $row_rs_existencias['rtrr']; ?></td>  
      <td align=center width="3%"><font size="2px"><?php echo $row_rs_existencias['ttl']; ?></td> 
       </size>
    </tr>
  </table>
  
   
<?php } while ($row_rs_existencias mysql_fetch_assoc($rs_existencias)); ?>

<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>

<?php
mysql_free_result
($rs_existencias);
?>
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 04:27.