vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   1 more left join problem :( (https://vborg.vbsupport.ru/showthread.php?t=74900)

miz 01-22-2005 10:13 PM

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

Andreas 01-22-2005 11:12 PM

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

miz 01-22-2005 11:17 PM

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

Dean C 01-22-2005 11:31 PM

Change:

SELECT *

to

SELECT DISTINCT session.userid, user.username

miz 01-22-2005 11:36 PM

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

Dean C 01-23-2005 09:45 AM

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]

Andreas 01-23-2005 09:58 AM

As I already said above, GROUP BY will not necessarily catch the last session ...

sabret00the 01-23-2005 10:01 AM

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.

miz 01-23-2005 10:21 AM

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 ?

Dean C 01-23-2005 10:26 AM

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 :)?


All times are GMT. The time now is 08:16 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.01023 seconds
  • Memory Usage 1,738KB
  • 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
  • (1)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete