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

Reply
 
Thread Tools Display Modes
  #11  
Old 01-23-2005, 10:49 AM
sabret00the's Avatar
sabret00the sabret00the is offline
 
Join Date: Jan 2003
Location: London
Posts: 5,268
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by miz
THANK YOU VERY MUCH
you guys have been replly helpfull to me

now please 1 more qustion

[SQL]$teamslist = $DB_site->query("
SELECT teams.*,user.username AS username, user.userid AS userid ,user.posts AS userposts, user.reputation AS userrep
FROM " . TABLE_PREFIX . "teams AS teams
LEFT JOIN user ON(teams.teamid = user.teamid)
WHERE teams.teamid > 1
GROUP BY teams.teamid
");[/SQL]

now i want it to take all userposts and count them togeder
is that possible ?
do a
PHP Code:
SELECT COUNT FROM user WHERE teamid $teamid 
Reply With Quote
  #12  
Old 01-23-2005, 11:02 AM
Dean C's Avatar
Dean C Dean C is offline
 
Join Date: Jan 2002
Location: England
Posts: 9,071
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You need to put parentheses around the asterix sabe :

[sql]
SELECT
COUNT(*) as total
FROM
user
[/sql]
Reply With Quote
  #13  
Old 01-23-2005, 11:36 AM
Dean C's Avatar
Dean C Dean C is offline
 
Join Date: Jan 2002
Location: England
Posts: 9,071
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Btw, the reason you were returning more than one result is because of the session timeout. You shouldn't need to group by at all if you add this clause to your query:

AND session.lastactivity > " . (TIMENOW - $vboptions['cookietimeout']) . "
Reply With Quote
  #14  
Old 01-23-2005, 11:48 AM
miz miz is offline
 
Join Date: Mar 2003
Posts: 416
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dean C
You'll need to do the count in a seperate query AFAIK

Btw can you show the query you used in the end to get the sessions working ?
this is the query

PHP Code:
$teamusers =  $DB_site->query("SELECT user.*  AS user
       FROM " 
TABLE_PREFIX "user 
       LEFT JOIN " 
TABLE_PREFIX "session
        ON(session.userid = user.userid)
       WHERE user.teamid='
$teamid
      GROUP BY user.userid ORDER BY session.lastactivity DESC
       "
); 
its also helped me in other query
i run about 100 tests lol and i surely can say that i understand
left joins better
now i want to run count inside the left join
and i need to update counters for each team :\
sucks

Quote:
Originally Posted by Dean C
You need to put parentheses around the asterix sabe :

[sql]
SELECT
COUNT(*) as total
FROM
user
[/sql]
but i dont want to count rows

i want to do like

user.posts =5 (userid=1)
user.posts=6 (userid=5)

total teams posts = 6
can i do query for that?

never mind i fixed it
this is the query

[SQL]
$teamslist = $DB_site->query("
SELECT teams.*,user.username AS username, user.userid AS userid ,user.posts AS userposts, user.reputation AS userrep,COUNT(user.posts) AS totalteamposts
FROM " . TABLE_PREFIX . "teams AS teams
LEFT JOIN user ON(teams.teamid = user.teamid)
WHERE teams.teamid > 1
GROUP BY teams.teamid
");
[/SQL]
Reply With Quote
  #15  
Old 01-23-2005, 11:52 AM
sabret00the's Avatar
sabret00the sabret00the is offline
 
Join Date: Jan 2003
Location: London
Posts: 5,268
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by miz
user.posts =5 (userid=1)
user.posts=6 (userid=5)
shouldn't total team posts = 11?
Reply With Quote
  #16  
Old 01-23-2005, 11:57 AM
miz miz is offline
 
Join Date: Mar 2003
Posts: 416
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

heh my mistake - to tierd you right shuold be 11
how am i doing that ?
do i need an exstra query for update ?
cuse now i will need to run 1 exstra query for each team...
Reply With Quote
  #17  
Old 01-23-2005, 12:03 PM
sabret00the's Avatar
sabret00the sabret00the is offline
 
Join Date: Jan 2003
Location: London
Posts: 5,268
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by miz
heh my mistake - to tierd you right shuold be 11
how am i doing that ?
do i need an exstra query for update ?
cuse now i will need to run 1 exstra query for each team...
no you need to do the count query that dean just gave you.

or if you've already got the posts, just do a mysql_num_rows() on the query, either will give you the info you desire.
Reply With Quote
  #18  
Old 01-23-2005, 12:08 PM
miz miz is offline
 
Join Date: Mar 2003
Posts: 416
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

you got me worng

i did this query

PHP Code:
$teamslist $DB_site->query("
     SELECT teams.*,user.username AS username,
      user.userid AS userid ,user.posts AS userposts,
      user.reputation AS userrep,
     COUNT(user.posts) AS totalteamposts,
     COUNT(user.reputation) AS totalteamrep
     FROM " 
TABLE_PREFIX "teams AS teams
      LEFT JOIN user  ON(teams.teamid = user.teamid)
     WHERE teams.teamid > 1
     GROUP BY teams.teamid
     
 "
);
 
 
 while (
$teams $DB_site->fetch_array($teamslist)) 
 {
     
     
     eval(
'$teamsbit .= "' fetch_template('teams_teamslistbit') . '";');
 
 
 } 
now in table teams i got teamposts
so i want to update teams.teamposts
now the value of total team posts is in
$teams['totalteamposts']
now my qustion is
if there a way to update teams.teamposts=$teams['totalteamposts']
without exstra query
or if i must use exstra query
do i need to run the query for each team (in the while loop)
so code should look like that

PHP Code:
$teamslist $DB_site->query("
      SELECT teams.*,user.username AS username,
       user.userid AS userid ,user.posts AS userposts,
       user.reputation AS userrep,
      COUNT(user.posts) AS totalteamposts,
      COUNT(user.reputation) AS totalteamrep
      FROM " 
TABLE_PREFIX "teams AS teams
       LEFT JOIN user  ON(teams.teamid = user.teamid)
      WHERE teams.teamid > 1
      GROUP BY teams.teamid
      
  "
);
  
  
  while (
$teams $DB_site->fetch_array($teamslist)) 
  {
      
      
$DB_site->query_first("UPDATE teams SET teamposts=$teams[totalteamposts] WHERE teamid=$teamid ");
      eval(
'$teamsbit .= "' fetch_template('teams_teamslistbit') . '";');
  
  
  } 
if i do it this way so i add 1 exstra query for each team
if i got 100 teams i add 100 query's
something i dont want to do
so im looking for other way...
any ideas ?
Reply With Quote
  #19  
Old 01-23-2005, 12:16 PM
sabret00the's Avatar
sabret00the sabret00the is offline
 
Join Date: Jan 2003
Location: London
Posts: 5,268
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

you're best bet would be to psuedo cache the data

in the while have

$count++
$row[$count] = $totalteamposts

then outside of the while add up the data from $row[0] -> $row[10] and beneath that to the update

saying that, not being sure if you can do that, it might now work.

actually ignore that, i know it's simpler than that, i'll have to come back to this, my minds gone blank

ahhh that's it try

$totalteamposts .= $teamposts[posts] . " + ";
then just remove the extra " + " at the end and throw it into a ceil()
Reply With Quote
  #20  
Old 01-23-2005, 12:19 PM
miz miz is offline
 
Join Date: Mar 2003
Posts: 416
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by sabret00the
you're best bet would be to psuedo cache the data

in the while have

$count++
$row[$count] = $totalteamposts

then outside of the while add up the data from $row[0] -> $row[10] and beneath that to the update

saying that, not being sure if you can do that, it might now work.

actually ignore that, i know it's simpler than that, i'll have to come back to this, my minds gone blank
heh
well dosent help me much
my problem isnt about counting cuse im doing it on the first query
my problem is to update
do i need to run exstra query for every team ?
there must be an other way... to update all teams in 1 query.
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 06:07 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.04700 seconds
  • Memory Usage 2,277KB
  • Queries Executed 11 (?)
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
  • (4)bbcode_php
  • (6)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
  • (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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete