[SQL] Requête SQL : obtenir un total
Bonjour,
sous le code suivant, j'aimerais obtenir le total genre SUM(Stock.Quantity), mais j'obtiens une erreur si je le fait.. quelqu'un peut-il me dire quoi mettre ? Merci d'avance !
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| <?
include ("connexion_stock.php");
?>
<html>
<head>
</head>
<body>
<?
$sqlconnect=odbc_connect($dsn,$username,$password);
$sqlquery="SELECT Products.ProductName, Products.ProductDesc, Products.type, Stock.Quality FROM Products, Stock where Products.ProductName=Stock.ProductName and Products.Type <> 'S'
Group by Products.ProductName, Products.ProductDesc, Products.type, Stock.Quality order by Products.ProductName, Products.Type;" or die (mysql_error());
$process=odbc_exec($sqlconnect, $sqlquery);
?>
<html>
<head>
<title>Etat du Stock</title>
<link href="../resolutions/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<p align="center"><b><font face="Arial" size="5">Eurosource Stock Report</font></b></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<table width="90%" border="0" align="center" cellpadding="1" cellspacing="1">
<tr class="tab04">
<td>
<div align="center">ProductName</div></td>
<td>
<div align="center">ProductDesc</div></td>
<td>
<div align="center">Quality</div></td>
<td>
<div align="center">Quantity</div></td>
<td>
<div align="center">Type</div></td>
</tr>
<?php while(odbc_fetch_row($process)){ $ProductName = odbc_result($process,"ProductName"); $ProductDesc = odbc_result($process,"ProductDesc"); $Type = odbc_result($process,"Type"); $Quality = odbc_result($process,"Quality"); ?>
<tr class="tab05">
<td><?php echo $ProductName ; ?></td>
<td><?php echo $ProductDesc ; ?></td>
<td><div align="center"><?php echo $Quality ; ?></div></td>
<td><div align="center"></div></td>
<td><div align="center"><?php echo $Type ; ?></div></td>
</tr><?php }odbc_close($sqlconnect); ?>
</table>
</body>
</html>
</body>
</html> |
Si je mets le SUM(Stock.QUantity) dans ma requête et donc ainsi :
Code:
1 2 3 4 5 6 7 8 9
| <?
$sqlconnect=odbc_connect($dsn,$username,$password);
$sqlquery="SELECT Products.ProductName, Products.ProductDesc, Products.type, Stock.Quality, SUM(Stock.Quantity)
FROM Products, Stock
where Products.ProductName=Stock.ProductName and Products.Type <> 'S'
Group by Products.ProductName, Products.ProductDesc, Products.type, Stock.Quality, Stock.Quantity
order by Products.ProductName, Products.Type ;" or die (mysql_error());
$process=odbc_exec($sqlconnect, $sqlquery);
?> |
en rajoutant donc le code suivant :
Code:
1 2 3 4 5 6 7 8
| <?php while(odbc_fetch_row($process)){ $ProductName = odbc_result($process,"ProductName"); $ProductDesc = odbc_result($process,"ProductDesc"); $Type = odbc_result($process,"Type"); $Quality = odbc_result($process,"Quality"); $Quantity = odbc_result($process,"Quantity"); ?>
<tr class="tab05">
<td><?php echo $ProductName ; ?></td>
<td><?php echo $ProductDesc ; ?></td>
<td><div align="center"><?php echo $Quality ; ?></div></td>
<td><div align="center"><?php echo $Quantity ; ?></div></td>
<td><div align="center"><?php echo $Type ; ?></div></td>
</tr><?php }odbc_close($sqlconnect); ?> |
j'ai l'erreur suivante :
Warning: odbc_result(): Field Quantity not found in c:\program files\easyphp1-8\www\eurosource-intranet\references\print_stock.php on line 43
la ligne 43 étant :
Code:
<?php while(odbc_fetch_row($process)){ $ProductName = odbc_result($process,"ProductName"); $ProductDesc = odbc_result($process,"ProductDesc"); $Type = odbc_result($process,"Type"); $Quality = odbc_result($process,"Quality"); $Quantity = odbc_result($process,"Quantity"); ?>
Merci de m'aider SVP...