![]() |
Help needed on first try at Database Query!
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(" btw, This code works but its only giving me the total of members not whats inside the "Field7" Table! |
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. |
I'm getting this error after using your code. :ermm:
Code:
Invalid SQL: 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: |
What are you using for the $searchclause var?
|
Quote:
Like I said this is my FIRST try at php/mysql coding! |
Get rid of the comma after the COUNT(field7) AS total, <-
That should sort it out |
Quote:
|
Can someone help plz??? :confused:
|
Please post the code you are using to display the result.
|
1 Attachment(s)
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(" |
No hope in getting this to work eh??? :ermm: :(
|
field7 contains numbers that you want to add up? Then here is the query that would work.
Code:
SELECT SUM(field7) AS total |
Quote:
Code:
// Weight Count |
Using that corrected code (in your last post), you must not output the variable $result_allweight, but you must output the variable
PHP Code:
You can also remove those comments; PHP Code:
|
Quote:
$result_allweight['total'] to my template I get Code:
The following error occurred when attempting to evaluate this template: |
In my FORUMHOME Template i have :
Code:
$header Code:
// ### START TEST WEIGHT COUNT ########################################## |
I guess I should give up on trying to get this working? :disappointed:
|
OK well since nobody else seems to know I'll do what I can to help.
One thing I might suggest also, is that you edit the custom profile field 'weight' and add this regular expression in the regular expression field: Code:
^[0-9]*$ Still it is up to you. Now, Lets see if we can't get this query to run successful. I ran apache on my computer to test the query myself, so I should eventually come up with something which I am positive works... I am testing it now while I am typing this message. --- Success so far! < I am now just doing a few quick last minute troubleshooting for any possible errors you may encounter, so I know in advance what to expect... > OK no errors encountered on my part. If any of your users have entered non-integer values for weight, it will omit them from the SUM(). I assumed it would error. Please tell me if this works for you. PHP Code:
Code:
$result_allweight[weight] Well, I hope this helps you, if you have any more troubles, I will see what I can do. Sorry for lengthy delay, it being Xmas and all. PS: Merry Xmas all. |
1 Attachment(s)
Davey,
I can't thank you enough for not giving up on my problem and making it work.. I just used your code on the site and its working GREAT! :) I have one last request if its not to hard to do.. The total weight loss is 2,221 Pounds (See attached image) The total comes up as "2221" is it hard to have it put in the " , " for the 1,000 mark so that it will show "2,221"? If its alot more work then I can deal with it staying the way it is but if its easy to place the " , " It would be great.. Thank for everyone's time that has worked on getting this to work for me.. I can't thank you all enough.. and To Davey please check your PM.. Thanks again!! Crow |
I guess no one wants to give this one a try! :ermm:
|
You'll need to put something like this in your PHP file:
PHP Code:
|
Quote:
|
Change this:
PHP Code:
PHP Code:
|
WOOHOO... Thank you very much!!!! :up: :classic: ;) :)
|
You're welcome :)
|
Sorry I killed my hard drive, I haven't checked back here for a long time.
No problem, I got your pm, check the reply. Happy to help. |
All times are GMT. The time now is 05:06 PM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|