PDA

View Full Version : Adding colum data from select results


fritz Jung
07-25-2002, 10:25 PM
First off... Thanks to those of you that helped yesterday. Appreciate it.

How do I sumarize a fields contents from all records returned from a select statement... IN PHP?

Exp.

two records returned with a column called 'visits'...

one record has 20 in the visits column and the other has 30

HOW can I get PHP to add up THIS COLUMN in those two records? ??

mordred
07-25-2002, 10:45 PM
Well, assuming that you use mysql, you could do the following:


$total = 0;
while ($row = mysql_fetch_assoc()) {
$total += $row["visits"];
}


Just have the $total variable outside your loop and each time you operate on one record, you add the new value.... this seems quite trivial to me that I'm under the impression that I misunderstood your problem... if you still have trouble achieving your goal, could you rephrase your question?