| | |
How do I add up all values of rows in a table???
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Dec 2007
Posts: 136
Reputation:
Solved Threads: 2
Hello,
I was wondering if anyone could help me as I am trying to add all the rows of a particular field in a MySQL table using PHP.
I have a table named members2 which has a field named points! What I want to be able to do is display the total number of points currently in the site that all members have!
But I have no idea how to do this and cannot seem to find anything when googling it!
Any help is much appreciated!
Justin
I was wondering if anyone could help me as I am trying to add all the rows of a particular field in a MySQL table using PHP.
I have a table named members2 which has a field named points! What I want to be able to do is display the total number of points currently in the site that all members have!
But I have no idea how to do this and cannot seem to find anything when googling it!
Any help is much appreciated!
Justin
you can try something like this:
php Syntax (Toggle Plain Text)
$query="Select points from members2"; $result=mysql_query($query); $total=0; while($row=mysql_fetch_array($result)) { $total=$total + $row['points']; } echo "Total is:" . $total;
•
•
Join Date: Jan 2007
Posts: 16
Reputation:
Solved Threads: 6
Easier:
If you want to limit the sum to certain sets of data, you will have to use the GROUP BY function in mysql. Learning about grouping and its associated functionality will help you avoid a lot of tedious, repetitive coding.
php Syntax (Toggle Plain Text)
$query="SELECT SUM(points) AS `total` from members2"; $result=mysql_query($query); while($row=mysql_fetch_assoc($result)) $total = $row['total'];
If you want to limit the sum to certain sets of data, you will have to use the GROUP BY function in mysql. Learning about grouping and its associated functionality will help you avoid a lot of tedious, repetitive coding.
Last edited by mcd; Aug 6th, 2008 at 11:42 pm.
•
•
•
•
Easier:
php Syntax (Toggle Plain Text)
$query="SELECT SUM(points) AS `total` from members2"; $result=mysql_query($query); while($row=mysql_fetch_assoc($result)) $total = $row['total'];
If you want to limit the sum to certain sets of data, you will have to use the GROUP BY function in mysql. Learning about grouping and its associated functionality will help you avoid a lot of tedious, repetitive coding.
php Syntax (Toggle Plain Text)
$query="SELECT SUM(points) AS `total` from members2"; $result=mysql_query($query); $total=mysql_result($result,0,"total");
![]() |
Similar Threads
- Pivot table in DataGrid (VB.NET)
- using javascript to dynamically add to existing html table (JavaScript / DHTML / AJAX)
- Datagrid to draw a table (C#)
- CSV file (C)
- Help with Dynamic Checkbox (PHP)
- Using MySQL with PHP - Tutorial by Herong (MySQL)
- PHP Arrays - I can't do em! (PHP)
- header information error (PHP)
- combo box (PHP)
- Drawing A Table On A Container(Panel) (Java)
Other Threads in the PHP Forum
- Previous Thread: simple sql query
- Next Thread: Allowing one user at a time to access a particular PHP Page
Views: 1223 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic ebooks echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla jquery js limit link login loop mail mediawiki menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select server sessions sms soap source space speed sql stored structure subdomain syntax system table tutorial update updates upload url validation validator variable video web xml youtube





