The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
![]()
I wasn't sure if this is the right section to post but I'll try here...
I'm trying to make a Database query, This will be my first one, So please be nice.. ok heres what I'm trying to do.. I have a site I'm doing for a support group. I have a userfield that members can choose a number, What I need is a database query that will add-up all the numbers and give a total... Heres my failed stab at it.. Code:
$result_allweight = $DB_site->query(" SELECT * FROM " . TABLE_PREFIX . "userfield $searchclause ORDER BY field7 "); $weightcount = $DB_site->num_rows($result_allweight); btw, This code works but its only giving me the total of members not whats inside the "Field7" Table! |
#2
|
|||
|
|||
![]()
If I understand what I think you're trying to accomplish...
Try this, see if it does what you need: PHP Code:
If anyone notices any obvious flaws in that above code, feel free to point them out, thanks. |
#3
|
|||
|
|||
![]()
I'm getting this error after using your code. :ermm:
Code:
Invalid SQL: SELECT COUNT(field7) AS total, FROM vb3_userfield mysql error: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM vb3_userfield' at line 2 mysql error number: 1064 The site is for a weightloss supprot group and during registering they have a userfield option (field7) where they can put in how much weight they lost. What I'd like is a total of all the members weight loss added up and shown on the forum home page. The code I posted in the first post works somewhat as its returning the amount of tables (members) and its not adding whats in the "Field7" table.. :disappointed: |
#4
|
|||
|
|||
![]()
What are you using for the $searchclause var?
|
#5
|
|||
|
|||
![]() Quote:
Like I said this is my FIRST try at php/mysql coding! |
#6
|
|||
|
|||
![]()
Get rid of the comma after the COUNT(field7) AS total, <-
That should sort it out |
#7
|
|||
|
|||
![]() Quote:
|
#8
|
|||
|
|||
![]()
Can someone help plz???
![]() |
#9
|
||||
|
||||
![]()
Please post the code you are using to display the result.
|
#10
|
|||
|
|||
![]() Quote:
Heres the code I'm using.. its give me a "Array" as the result. (see attached image) Code:
$result_allweight = $DB_site->query_first(" SELECT COUNT(field7) AS total FROM " . TABLE_PREFIX . "userfield "); /* $result_allweight['total'] - should return the total value. */ |
![]() |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|