Hi everyone,
I'm trying to make a SUM of the values of a previous querry.
It prints the results all right but instead of the sum in the end I get - Resource id #5.
If i do this
$number = mysql_query("SELECT sum(prix) AS sum FROM compta WHERE 1");
$sum = mysql_fetch_array($number);
echo " $number ";
I get "Resource id #5"
if I do
echo " $sum ";
I get "Array"
I don't have any idea what does it mean and what exactly happens. I tried 100s of ways but it always gives me the same shit. I'll give you my complete code...maybe the problem is somewhere else.
Thanks a lot!
<?php
if ($submit){
$sql = 'SELECT * FROM `compta` WHERE 1';
if ($prix)
$sql .= " AND `prix`='$prix'";
$result = mysql_query ($sql);
if (!$result){
print "erreur $sql <br>";
exit;
}
?>
<table width="400">
<thead>
<tr>
<td><p align="center">prix</td>
</tr>
</thead>
<tbody>
<?php
while ($row = mysql_fetch_array ($result)){
echo "<tr>";
echo "<td>" . $row['prix'] . "";
echo "</tr>";
}
$number = mysql_query("SELECT sum(prix) AS sum FROM compta WHERE 1");
$sum = mysql_fetch_array($number);
echo " $number ";
?>