vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Counting how many X is in a field for each id in a table (https://vborg.vbsupport.ru/showthread.php?t=45191)

DrkFusion 10-30-2002 10:52 AM

Counting how many X is in a field for each id in a table
 
Hi guys,

I would like to know how I would go about running a sql php code that will tell me how many times the forumidX shows up in a field in the WHOLE table.

For instance forumid 8 from the field5 in the profilefields table.

Thanks in advance, appreciate all and any help.
-Arunan

Xenon 10-30-2002 12:15 PM

hmm, not sure if i understand you right, but i think you want to have this:

PHP Code:

$var=$DB_site->query_first("SELECT COUNT(*) as counter FROM userfields WHERE field5='8'"); 

$var[counter] would be your value how much users have 8 in field5

DrkFusion 10-30-2002 06:12 PM

Ah Thanks Xenon, I will try it out.

Thanks again, you always are a great help
-Arunan

DrkFusion 10-30-2002 09:58 PM

Well, I am doing a top 5 kinda thing, how would I do something like that?

I want to find out how many people have 1 forumid in field5 and make that the top forumid kinda thing. :-/

Thanks

Xenon 10-31-2002 10:16 AM

ohhh, thats a bit ahead of my sql-knowledge.
don't know if this is even possible

i just know a (real) bad but working way, but it is very very hardcoded:

PHP Code:

$var=$DB_site->query_first("SELECT SUM(IF(field5='1',1,0) as forum1, SUM(IF(field5='2',1,0) as forum2 FROM userfields"); 

so you can use $var[forum1], $var[forum2] and so on (if you make a longer query ;)) and can compare all these....

i know, it's veryy bad, but i don't know another way ....

DrkFusion 10-31-2002 10:59 AM

Thanks Stefan,

Well I guess I will take an easier way out, I will make the value of the field increase by 1 every time the forumid is added to there profile field, now how do I stop users from doing it more than once?

Sorry, if I am asking too many questions :( I am yet a weee litttle Php Padwan, still learning the ways :)
-Arunan

Xenon 10-31-2002 03:18 PM

well you have to check if they already have had a id inserted, and reduce the value at this id by one and then increase the value for the new id...

with $bbuserinfo[fieldx] you can acces the old value and compare it with the new one befor the new value is entered to the db

DrkFusion 11-01-2002 09:21 PM

I put the fieldX+1, but it seems to be adding 13 :-/

-Arunan


All times are GMT. The time now is 04:35 AM.

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.01444 seconds
  • Memory Usage 1,720KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (8)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete