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 01-22-2005, 10:13 PM
miz miz is offline
 
Join Date: Mar 2003
Posts: 416
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 1 more left join problem :(

ok i tried to run this query
[SQL]
$teamusers = $DB_site->query("SELECT * FROM " . TABLE_PREFIX . "user
LEFT JOIN " . TABLE_PREFIX . "session ON(session.userid = user.userid) WHERE user.teamid='$teamid' ");
[/SQL]

this query should get all users which in $teamid and their online status

now query works fine but
if userid show up few times in sessions
then its show up the user few times
but i want it to show each user only 1 time

what am i doing worng ?

thanx for help
Reply With Quote
  #2  
Old 01-22-2005, 11:12 PM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This is tricky ...

Which information from the session table do you need?
Because if you GROUP BY session.userid, it will just take one session for each user, but not necessarily the active one
Reply With Quote
  #3  
Old 01-22-2005, 11:17 PM
miz miz is offline
 
Join Date: Mar 2003
Posts: 416
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

hmmm
this is what im tring to do

PHP Code:
$datecut TIMENOW $vboptions['cookietimeout'];
 
$teamusers =  $DB_site->query("SELECT * FROM " TABLE_PREFIX "user 
      LEFT JOIN " 
TABLE_PREFIX "session  ON(session.userid = user.userid) WHERE user.teamid='$teamid'  ");
 while (
$members $DB_site->fetch_array($teamusers))
     {
 
$useronline =    fetch_online_status($members);
 } 
now basiclly this query should give me
list of users which in $teamid and their online status

but its get ++++ed up some where
Reply With Quote
  #4  
Old 01-22-2005, 11:31 PM
Dean C's Avatar
Dean C Dean C is offline
 
Join Date: Jan 2002
Location: England
Posts: 9,071
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Change:

SELECT *

to

SELECT DISTINCT session.userid, user.username
Reply With Quote
  #5  
Old 01-22-2005, 11:36 PM
miz miz is offline
 
Join Date: Mar 2003
Posts: 416
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dean C
Change:

SELECT *

to

SELECT DISTINCT session.userid, user.username
ok i tested it
and its show me only 1 time the user
but its also give me worng online status


btw what the word DISTINCT means ?

EDIT :
=====
for online status you should get also session.lastactivity
i tired add it and its again gave me 2 user names
Reply With Quote
  #6  
Old 01-23-2005, 09:45 AM
Dean C's Avatar
Dean C Dean C is offline
 
Join Date: Jan 2002
Location: England
Posts: 9,071
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

DISTINCT means you only return unique rows. Ummm try:

[sql]
SELECT
*
FROM
" . TABLE_PREFIX . "user
LEFT JOIN
" . TABLE_PREFIX . "session ON(session.userid = user.userid)
WHERE
user.teamid='$teamid'
GROUP BY
userid
ORDER BY
session.lastactivity DESC
[/sql]
[/sql]
Reply With Quote
  #7  
Old 01-23-2005, 09:58 AM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

As I already said above, GROUP BY will not necessarily catch the last session ...
Reply With Quote
  #8  
Old 01-23-2005, 10:01 AM
sabret00the's Avatar
sabret00the sabret00the is offline
 
Join Date: Jan 2003
Location: London
Posts: 5,268
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

deans would probably work if you select distinct and remove the group by as it's getting the last session to check the timeout it should return the wanted information.
Reply With Quote
  #9  
Old 01-23-2005, 10:21 AM
miz miz is offline
 
Join Date: Mar 2003
Posts: 416
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 ?
Reply With Quote
  #10  
Old 01-23-2005, 10:26 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'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 ?
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 10:11 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.04390 seconds
  • Memory Usage 2,256KB
  • 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
  • (1)bbcode_php
  • (1)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