This question already has an answer here:
I have a table table_log
filled with logs with different IDs but some of those logs have the same ID. I have to get the sum of column counter
of those with the same ID id
then display the results a column total_count
. This is my query:
SELECT id, SUM(counter) AS total_count FROM table_log GROUP BY id
I have to display this in a table column using PHP. This is what I have:
- $sql = "SELECT id, SUM(counter) AS total_count FROM table_log GROUP BY id";
- $row = mysql_fetch_assoc($sql);
- $sum = $row['total_count'];
- $data .= "<td style='width: 200px;' align=center >". $sum ."</td>";
It's not appearing in the table. What should I input instead?
EDIT : I didn't choose to use this. The company did.
</div>