I´m trying to get a sum from the column of the repeated values that was selected in a form before, but i can´t even show the result, is there something wrong with this code?
DB Structure
table carros
-id
-matricula
-marca
table movimentos
-id
-matricula
-marca
-fornecedor
-tipo
-despesa
-observacoes
i have a form in the file “verificar.dwt.php” that contains a dropdown list with all the values in “matricula” (from the table carros) and when it selects the respective “matricula” it goes to “extra1.dwt.php” where it shows a table with all the repeated rows that have the same “matricula” value.
What i want to show now is the sum of that repeated rows.
<a href='verificar.dwt.php'>Voltar atrás</a>
<div align="center"><?
include 'configmov.dwt.php';
$tableName='movimentos';
$matricula = mysql_real_escape_string($_POST['matricula']);
$sql="SELECT matricula, marca, despesa FROM ".$tableName." WHERE matricula = '".$matricula."'";
$result=mysql_query($sql);
$result1 = mysql_query('SELECT SUM(value) AS value_sum FROM despesa');
$row1 = mysql_fetch_assoc($result1);
$sum = $row1['value_sum'];
$n=1;
echo "Os seus resultados: <p>";
echo "<table border=0>";
echo "<tr bgcolor='#CCFFCC'>";
echo "<td style='width: 100px;'>Matricula</td>";
echo "<td style='width: 100px;'>Marca</td>";
echo "<td style='width: 100px;'>Despesa</td>";
echo "</tr>";
while($row = mysql_fetch_array($result)){
echo "<tr bgcolor='#CCCCCC'>";
echo "<td style='width: 100px;'>".$row['matricula']."</td>";
echo "<td style='width: 100px;'>".$row['marca']."</td>";
echo "<td style='width: 100px;'>".$row['despesa']."</td>";
echo "</tr>";
echo $sum;
}
if you want to show it then you must show it on a column under a row but you closed your row attribute before displaying it may be it creates problem.and one more thing you put this query
is despesa table name?? as i think it is colname if it is colname then your query should look like this