Ver Mensaje Individual
  #1 (permalink)  
Antiguo 30/08/2010, 15:02
aeroplane10
 
Fecha de Ingreso: agosto-2010
Mensajes: 6
Antigüedad: 14 años, 5 meses
Puntos: 0
Sumar y restar numeros con PHP

Hola gente!
Tengo un problemita que me esta quemando la cabeza desde hace dias.
Tengo una base de datos con 4 campos:

item_no, qty_on_hand, qty_on_ord, qty_allocated

Dentro de los registros de mis campos hay varios cientos de filas donde las cantidades y valores varian siempre, principalmente (item_no).

Por ejemplo:

│ item_no (AAA-100-10)│ qty_on_hand (30)│ qty_on_ord (10)│ qty_allocated (10)│


Temgo mi codigo PHP que meidante (include) se conecta a mi base de datos desde otro archivo PHP, recoje esos valores relacionados con la busqueda del usuario y los muestra en una pagina html.

Hasta ahi voy bien, pero me gustaria agregar a mi PHP otra columna que muestre un total calculado, por ejemplo:

qty_on_hand (30)│ qty_allocated (10)│ Total (40)

A continuacion les paso el codigo que tengo hasta ahora haber si me pueden dar una manito

Código PHP:
<html>
<head>
  <title>Inventory Query</title>
  <style type="text/css">
  
  h1 {
      font:Arial, Helvetica, sans-serif;
      font-size:16px;
      width: 450px;
      background-color:#FBB;
  }
      
  table {
      background-color:#FF0;
  }
  
  th {
      width: 220px;
      text-align: left;
  }
  
  </style>
 </head>
<body>
<h1>National Tree - Inventory Query</h1>

<form method="post" action="inventory.php">
<input type="hidden" name="submitted" value="true" />

<label>Enter Item Number:<input type="text" name="criteria" /></label>

<input type="submit" />

</form>

<?php

if (isset($_POST['submitted'])) {
// connect to the database
include('xxxxxxx.php');

$upc 'item_no';
$criteria $_POST['criteria'];
$query =  "SELECT * FROM IMINVLOC_SQL WHERE $upc LIKE '%".$criteria."%'";
$result mysqli_query($dbcon$query) or die('error getting data');
$num_rows mysqli_num_rows($result);

echo 
"$num_rows results found";
echo 
"<table>";
echo 
"<tr> <th>Item Number</th> <th style='text-align:right'>Qty On Hand</th> <th style='text-align:right'>Qty On Order</th> <th style='text-align:right'>Qty Allocated</th> </tr>";

while (
$row mysqli_fetch_array($resultMYSQLI_ASSOC)) {

    echo 
"<tr><td>";
    echo 
$row ['item_no'];
    echo 
"</td><td style='text-align:right'>";
    echo 
$row ['qty_on_hand'];
    echo 
"</td><td style='text-align:right'>";
    echo 
$row ['qty_on_ord'];
    echo 
"</td><td style='text-align:right'>";
    echo 
$row ['qty_allocated'];
    echo 
"</td></tr>";
    
}

echo 
"</table>";
    
    
    
// end of main statment

?>
<br>
Please don't use (space) on your Criteria!
</body>
</html>
Si les interesa el codigo obviamente que lo pueden usar para su propio probecho y si quieren ver que es lo que muestra mi HTML al realizar una busqueda en el mismo, solo cliqueen [URL="http://nationaltree.com/stock/inventory.php"]aqui[/URL].

Desde ya muchas gracias a todos!!!!