Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 12-16-2004, 09:50 PM
EvilCrow EvilCrow is offline
 
Join Date: Aug 2002
Location: Detroit, Michigan. US
Posts: 55
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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("
		SELECT * FROM " . TABLE_PREFIX . "userfield $searchclause ORDER BY field7
	");

	$weightcount = $DB_site->num_rows($result_allweight);
I need the query to go inside the "Userfield" and count the numbers inside "field7" and give me a total for all..
btw, This code works but its only giving me the total of members not whats inside the "Field7" Table!
Reply With Quote
  #2  
Old 12-17-2004, 12:34 AM
Davey Davey is offline
 
Join Date: Nov 2002
Location: England
Posts: 383
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If I understand what I think you're trying to accomplish...

Try this, see if it does what you need:

PHP Code:
$result_allweight $DB_site->query_first("
   SELECT COUNT(field7) AS total,
   FROM " 
TABLE_PREFIX "userfield
   
$searchclause
"
);
/*
$result_allweight['total'] - should return the total value.
*/ 
This is an untested piece of code, I have no idea if it even works. If it doesn't, please post back stating any errors you get, I will do my best to help if I can.

If anyone notices any obvious flaws in that above code, feel free to point them out, thanks.
Reply With Quote
  #3  
Old 12-17-2004, 08:56 AM
EvilCrow EvilCrow is offline
 
Join Date: Aug 2002
Location: Detroit, Michigan. US
Posts: 55
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Let me explain better of what I'm trying to do here..
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:
Reply With Quote
  #4  
Old 12-17-2004, 09:45 AM
Brad Brad is offline
 
Join Date: Nov 2001
Posts: 4,765
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What are you using for the $searchclause var?
Reply With Quote
  #5  
Old 12-17-2004, 09:55 AM
EvilCrow EvilCrow is offline
 
Join Date: Aug 2002
Location: Detroit, Michigan. US
Posts: 55
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Brad.loo
What are you using for the $searchclause var?
erm... I guess nothing. :disappointed:
Like I said this is my FIRST try at php/mysql coding!
Reply With Quote
  #6  
Old 12-17-2004, 01:59 PM
dimopoulos dimopoulos is offline
 
Join Date: Dec 2004
Posts: 11
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Get rid of the comma after the COUNT(field7) AS total, <-

That should sort it out
Reply With Quote
  #7  
Old 12-17-2004, 03:03 PM
EvilCrow EvilCrow is offline
 
Join Date: Aug 2002
Location: Detroit, Michigan. US
Posts: 55
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by dimopoulos
Get rid of the comma after the COUNT(field7) AS total, <-

That should sort it out
Did that and now I don't get any errors but insted of posting a total its only posting "Array"?? :disappointed:
Reply With Quote
  #8  
Old 12-19-2004, 11:23 AM
EvilCrow EvilCrow is offline
 
Join Date: Aug 2002
Location: Detroit, Michigan. US
Posts: 55
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Can someone help plz???
Reply With Quote
  #9  
Old 12-19-2004, 01:15 PM
Paul M's Avatar
Paul M Paul M is offline
 
Join Date: Sep 2004
Location: Nottingham, UK
Posts: 23,748
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Please post the code you are using to display the result.
Reply With Quote
  #10  
Old 12-20-2004, 11:29 AM
EvilCrow EvilCrow is offline
 
Join Date: Aug 2002
Location: Detroit, Michigan. US
Posts: 55
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Paul M
Please post the code you are using to display the result.

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. 
*/
Attached Images
File Type: gif error.gif (607 Bytes, 0 views)
Reply With Quote
Reply


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

Forum Jump


All times are GMT. The time now is 07:44 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
  • Page Generation 0.04017 seconds
  • Memory Usage 2,273KB
  • Queries Executed 12 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_code
  • (1)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (1)postbit_attachment
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • postbit_attachment
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete