Register Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools
  #1  
Old 08 Jun 2007, 03:49
aggiefan aggiefan is offline
 
Join Date: Apr 2005
SQL Statement help - Sum - Resource ID #81

I'm coding a page in a new hack I'm building and am trying to sum a column using a where condition. Here's the code I'm using:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Essentially, I want the sum of all values in the donation_amount column where the donation_sport column is football. I just want to display the result -- no other special use for it. I'm getting a "RESOURCE ID #81" when I print $pledgeamount, so thought maybe I had to clean it up and so did the $pledge code part...that just comes up blank.

I've done hacks before for Vbulletin, but never had to use a Sum statement. Is there something special I need to do?
__________________
Owner of http://www.aggiefans.com
Our Custom Hacks:
Reputation Report
vBContest (college pickem script)
Reply With Quote
  #2  
Old 08 Jun 2007, 04:13
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Instead of using the query() function, use query_first() which will also fetch the results as an array.
Reply With Quote
  #3  
Old 08 Jun 2007, 04:31
aggiefan aggiefan is offline
 
Join Date: Apr 2005
Thanks for the reply. I was able to find a work-around (make it work) by looking at the code for vbBookie...i figured they were adding something in there. With that said, here's code that works (maybe not efficient, but a starting point for somebody in the same position I was).

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

PRINT "$finalamount" shows the correct sum, so that's about all I needed to be functional here. I may need to expand off this, but it's a start.
__________________
Owner of http://www.aggiefans.com
Our Custom Hacks:
Reputation Report
vBContest (college pickem script)
Reply With Quote
  #4  
Old 08 Jun 2007, 04:33
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
query_first() basically calls query_read() and fetch_array() to save time.
Reply With Quote
  #5  
Old 08 Jun 2007, 11:15
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Real name: Hanson
And calls a free_result as well.
__________________
View My Modifications
29 Releases and Counting... Latest Modification: dmActivityStream - vBookie Integration (4.x)

Please do not PM me to ask for support - please use the relevant thread or forum.
Reply With Quote
  #6  
Old 10 Jun 2007, 19:25
turnipofdoom turnipofdoom is offline
 
Join Date: May 2004
The reason the first query does not work is because the result field name ends up something like SUM(donation_amount), not donation_amount as you expected. With SUM you generally use AS.

SELECT SUM(my_field) AS SomeName FROM X GROUP BY Y;
Reply With Quote
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
vBulletin Resource King Kovifor vBulletin 3.5 Add-ons 15 05 Jul 2006 20:52

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools

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


New To Site? Need Help?

All times are GMT. The time now is 06:57.

Layout Options | Width: Wide Color: