Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
help in PHP Mysql Sum
Old 12-08-2008, 10:14 PM help in PHP Mysql Sum
Junior Talker

Posts: 1
Name: Karlo Ian
Trades: 0
hi there.. im a newbie at php and got a probe using the mysql sum. I know how to use it in only one table but if join the table i don't know how to the sample codes ex. this code works cause im only using one table
PHP Code:
$query "SELECT SerialNumber, SUM(Grade) FROM D03Registrar Where SerialNumber = "$serial"  AND RegistrationNumber = '"$_GET['regno'] ."' GROUP BY SerialNumber "
but in this code i dont know how to use the sum
PHP Code:
$query "SELECT d.Code,d.PFinal, d.FFinal, d.Grade,
          d.TeacherName, t.Description,d.Day, d.room, d.time, t.Subject, t.Number, t.Units "
.
 
"FROM D03Registrar d LEFT JOIN tablenewA3 t  ".
    
"ON d.Code = t.CurCode where SerialNumber = "$serial ." AND RegistrationNumber = '"$_GET['regno'] ."'"
thanks for your help..
karloian is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-09-2008, 04:51 AM Re: help in PHP Mysql Sum
stoot98's Avatar
Ultra Talker

Posts: 427
Name: Stuart
Location: Glasgow, Scotland
Trades: 0
You need a Group By clause for a SUM to work with multiple fields in the select list.
stoot98 is offline
Reply With Quote
View Public Profile
 
Old 12-09-2008, 08:42 AM Re: help in PHP Mysql Sum
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Just remember that you have to specify in your group by clause every columns you use in the select output.
In your case, it would be something like this:
PHP Code:
$query=<<<SQL
SELECT 
  d.Code,d.PFinal, d.FFinal, sum(d.Grade),d.TeacherName, t.Description,d.Day, d.room, d.time,
  t.Subject, t.Number, t.Units
FROM D03Registrar d 
  LEFT JOIN tablenewA3 t ON d.Code = t.CurCode 
WHERE SerialNumber = 
{$serial}
AND RegistrationNumber = '
{$_GET['regno']}'
GROUP BY d.Code,d.PFinal, d.FFinal, d.Grade,d.TeacherName, t.Description,d.Day, d.room, d.time,t.Subject, t.Number, t.Units
SQL; 
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to help in PHP Mysql Sum
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.11828 seconds with 12 queries