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 03-12-2003, 06:15 PM
Tryfwar Tryfwar is offline
 
Join Date: Nov 2001
Location: Nottingham, UK
Posts: 45
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default SQL syntax help

I was hoping that somebody might be able to help me with this problem:

Firstly, I have created a new table in my forums db called userclass and in it there are 2 fields: userclassid & title.

Then i have added a field to the user table called 'userclassid' as well and have successfully been able to modify the user.php to enable me to assign a class title to each user.

In addition to this i have added a field to the usergroup table called 'rollcall' which is simply a 1 or 0, so i can assign wether or not i wish for these usergroups to appear in the rollcall. (just like the showgroups function does for the showgroups.php)

The problem i have is in this query that was originaly from the showgroups.php, i cannot work out how i should write it

I would like it so that it will list users in groups of class and only those who have been assigned '1' in the usergroup.rollcall table.

The below Query displays them almost as i want but it lists each user 5 times!! lol oh and it also seems to display users regardless of the WHERE clause :/


PHP Code:
$users $DB_site->query("
    SELECT
        
$classfieldselect userclass.title, user.userid, user.username, user.userclassid,  user.userclassid,
         user.usergroupid
        FROM userclass
        LEFT JOIN user ON (userclass.userclassid = user.userclassid)
        LEFT JOIN userfield ON (userfield.userid = user.userid)
        LEFT JOIN usergroup ON usergroup.rollcall
        WHERE usergroup.rollcall = 1
    "
); 
Thanks in advance to anyone who can help
Reply With Quote
  #2  
Old 03-12-2003, 06:57 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

try that one:

PHP Code:
$users $DB_site->query("
    SELECT DISTINCT
        
$classfieldselect userclass.title, user.userid, user.username, user.userclassid,  user.userclassid,
         user.usergroupid
        FROM user
        LEFT JOIN userclass ON (userclass.userclassid = user.userclassid)
        LEFT JOIN userfield ON (userfield.userid = user.userid)
        LEFT JOIN usergroup ON (usergroup.usergroupid = user.usergroupid)
        WHERE usergroup.rollcall = 1
    "
); 
Reply With Quote
  #3  
Old 03-12-2003, 07:06 PM
Tryfwar Tryfwar is offline
 
Join Date: Nov 2001
Location: Nottingham, UK
Posts: 45
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

woah! nice one !!!

Works a treat!!!

Thanks alot Xenon ... juuuuuust one more thing: its in reverse alphabetical order, anyway to switch that ?

The usernames are i mean.
Reply With Quote
  #4  
Old 03-12-2003, 07:27 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

welcome

add ORDER BY username ASC after the where clause
Reply With Quote
  #5  
Old 03-12-2003, 07:53 PM
Tryfwar Tryfwar is offline
 
Join Date: Nov 2001
Location: Nottingham, UK
Posts: 45
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks a million made me very happy
Reply With Quote
  #6  
Old 03-13-2003, 11:22 AM
Tryfwar Tryfwar is offline
 
Join Date: Nov 2001
Location: Nottingham, UK
Posts: 45
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

how can i make it so that it WONT list members who haven't yet got a 'userclassid' please?

I've tried using the NOT 0 syntax but i keep getting errors
Reply With Quote
  #7  
Old 03-13-2003, 11:30 AM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

use that where:[sql]WHERE usergroup.rollcall = 1 AND user.userclassid != 0[/sql]
Reply With Quote
  #8  
Old 03-13-2003, 11:35 AM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

use mine
Reply With Quote
  #9  
Old 03-13-2003, 11:35 AM
Tryfwar Tryfwar is offline
 
Join Date: Nov 2001
Location: Nottingham, UK
Posts: 45
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Code:
 SELECT DISTINCT
         userclass.title, user.userid, user.gender, user.username, user.userclassid,
         user.usergroupid
        FROM user
        LEFT JOIN userclass ON (userclass.userclassid = user.userclassid !=0)
        LEFT JOIN userfield ON (userfield.userid = user.userid)
        LEFT JOIN usergroup ON (usergroup.usergroupid = user.usergroupid)
		WHERE usergroup.rollcall = 1 ORDER BY username ASC
    ");
just worked it out!
err its different to yours
Reply With Quote
  #10  
Old 03-13-2003, 11:37 AM
Tryfwar Tryfwar is offline
 
Join Date: Nov 2001
Location: Nottingham, UK
Posts: 45
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

have hehe, thanks again Xenon, your a star
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 09:49 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.04282 seconds
  • Memory Usage 2,260KB
  • 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_code
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)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