The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
![]()
Sorry, I seem to have left my PHP books at the office, but I had a quick question that someone should hopefully be able to answer.
I'm writing a little stat hack for my members that will count the number of users of various interests that I'll display in my Site Stats row of the main forum page. My stats will be generated off the custom "field5" (listed in the DB as "field5"), which is a pulldown that lists 5 or 6 options, and the member can pick one. I don't care about usernames, etc. I just want raw stats. This is example code of what I wanted to use, but I'm not sure about the array stuff. I want the text key for the array to match the text of the option in the pulldown, and increment it if there's a match from the database row from my select statement. Code:
$field5stat = array(); $dbquery = $DB_site->query("SELECT field5 FROM " . TABLE_PREFIX . "userfield ASC"); while ($queryrow = $DB_site->fetch_array($dbquery)) { $field5stat[$queryrow['field5']]++ } Will that work, or is my syntax of either the array or incrementing wrong? Thanks for any assistant, my PHP coding skills are rather rusty as I haven't programmed in it for about 4 years *laughs* |
#2
|
||||
|
||||
![]()
your best bet would be to scrap the way you done it in order of something alot simpler
PHP Code:
|
#3
|
|||
|
|||
![]() Quote:
I get: $field5stat[0] aka ['blue'] = 25 $field5stat[1] aka ['red'] = 5 ... $field5stat[7] aka ['orange'] = 10 count($field5stat) returns 8 (there are 8 indexes) My problem now seems to be that I can't pull up the array values by the numerical key, only the textual key. I though arrays can have both the numerical AND textual key values. :disappointed: Say I now wanted to loop through the array and spit out the textual key and the value (not the key#) to get a listing of something like: blue 25 red 5 ... orange 10 I was trying to do a loop like: PHP Code:
*sighs* |
#4
|
||||
|
||||
![]()
[sql]SELECT COUNT(field5) AS total FROM userfield[/sql]
Run that query and see if it's what you want? Little confused as to what you're doing here ![]() |
#5
|
|||
|
|||
![]() Quote:
I'll give an example of what I'm trying to do. I have a custom field in the UCP, which one is "My favorite color is:" and there's a pull down of 8 options to choose from. (red, blue, green, etc..) This column is called field5. I want to scan the column and display how many people like red, blue, green, etc. The reason I didn't go with sabret00the's original suggestion was because then I'd have to change the code if I decided to add another option for the field (a new color). Thanks for your suggestion though. |
#6
|
||||
|
||||
![]() Quote:
Quote:
|
#7
|
||||
|
||||
![]() PHP Code:
|
#8
|
|||
|
|||
![]()
What about a:
[sql]SELECT field5, COUNT(field5) FROM userfield GROUP BY field5;[/sql] wouldn't that do the trick? |
#9
|
||||
|
||||
![]()
MarcoH64 is right, basically this query should do the work.
But i'd change it a bit to make the results easier to use: [sql]SELECT field5, COUNT(field5) AS total FROM userfield GROUP BY field5[/sql] |
#10
|
|||
|
|||
![]()
sorry, yes you're right Kirby, should have added that. Bit easier to use on scripts
![]() |
![]() |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|