Facebook  Twitter 

SMFHacks.com

+-

SMFHacks.com

+- User Information

Welcome, Guest.
Please login or register.
 
 
 
Forgot your password?

+- Forum Stats

Members
Total Members: 4255
Latest: andreios
New This Month: 3
New This Week: 1
New Today: 0
Stats
Total Posts: 43259
Total Topics: 7518
Most Online Today: 297
Most Online Ever: 2482
(April 09, 2011, 07:02:45 pm)
Users Online
Members: 0
Guests: 276
Total: 276

Author Topic: Finding the sum of a column MYSQL  (Read 5915 times)

0 Members and 1 Guest are viewing this topic.

Offline shuban

  • Hero Member
  • *****
  • Posts: 665
    • View Profile
    • Biology Forums
Finding the sum of a column MYSQL
« on: July 11, 2016, 12:32:34 pm »
I'm trying to get the grandtotal of the column numPlays, so I used this query:

Code: [Select]
global $db_prefix;

$results2 = db_query("
SELECT
SUM(numPlays)
FROM {$db_prefix}arcade_games", __FILE__, __LINE__);

When I echo $results2; I don't get the sum (I get Resource id # or something), what am I doing wrong?

Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 16436
    • View Profile
Re: Finding the sum of a column MYSQL
« Reply #1 on: July 11, 2016, 12:38:36 pm »
you still have to do mysql_fetch_assoc after that to get the row
i normally do SUM(numPlays) as total
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

Offline shuban

  • Hero Member
  • *****
  • Posts: 665
    • View Profile
    • Biology Forums
Re: Finding the sum of a column MYSQL
« Reply #2 on: July 11, 2016, 12:49:15 pm »
Took your advice, still no dice:

Code: [Select]
$results_2 = mysql_fetch_assoc(mysql_query('SUM(numPlays) as total FROM '.$db_prefix.'arcade_games'));

echo $results_2['total'];

This time nothing is displayed and I get the error: Warning: mysql_fetch_assoc() expects parameter 1 to be resource

Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 16436
    • View Profile
Re: Finding the sum of a column MYSQL
« Reply #3 on: July 11, 2016, 12:50:09 pm »
You still need to SELECT SUM
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/
Agree Agree x 1 View List

Offline shuban

  • Hero Member
  • *****
  • Posts: 665
    • View Profile
    • Biology Forums
Re: Finding the sum of a column MYSQL
« Reply #4 on: July 11, 2016, 12:50:54 pm »
thanks, SMFHacks!

 

Related Topics

  Subject / Started by Replies Last post
1 Replies
4043 Views
Last post January 31, 2008, 05:28:27 pm
by SMFHacks
0 Replies
2771 Views
Last post October 12, 2010, 05:49:10 pm
by mxcape21
11 Replies
9850 Views
Last post February 06, 2012, 03:44:53 am
by spikeweb
2 Replies
5259 Views
Last post July 09, 2016, 03:28:39 pm
by shuban
1 Replies
3576 Views
Last post August 17, 2016, 06:12:18 pm
by SMFHacks

+- Recent Topics

No thumbnails on new uploads by SMFHacks
March 27, 2024, 02:10:41 pm

Display the Contact Page for guests by SMFHacks
March 27, 2024, 10:55:43 am

is it possible to add support for odysee.com by fvlog19
March 21, 2024, 08:47:51 am

Request for admin notification by davejo
March 10, 2024, 01:31:59 am

I need help with torrent upload by Ineedsmfhelp
March 09, 2024, 10:01:13 pm

an idea for new mod (( content type with different display )) by SMFHacks
February 27, 2024, 01:36:27 pm

[Mod] RSS Feed Poster by SMFHacks
February 27, 2024, 11:57:18 am

find duplicate pictures by fvlog19
February 14, 2024, 02:22:40 pm

Error uploading video. by SMFHacks
February 08, 2024, 02:04:16 pm

Gallery icon as last added image by fvlog19
February 01, 2024, 01:04:56 pm

Powered by EzPortal