Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
  #1  
Old 11-22-2009, 10:47 PM
MyPornLife.info MyPornLife.info is offline
 
Join Date: Apr 2009
Posts: 40
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default usergroup permission based SQL query

in a custom page...

i hav to use this:
Code:
$query = "SELECT * FROM " . TABLE_PREFIX . "vbtable WHERE cID = ??? ORDER BY dateline DESC";
in the category table (in mysql) there are six categories.... (cID = 1,2,3,4,5,6) & each category has specific usergroup based permission.
Like only admin group can view content of category 4 (cID=4; cPermission=6)

now i want that query, check if the current user is belong to usergroup-6 (admin)....if so it will get row from mysql table whos cID is 4....otherwise it will skip those row.
Reply With Quote
  #2  
Old 11-23-2009, 01:02 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm not sure if I understand what you're asking, but maybe something like (untested):

Code:
$where = ($vbulletin->userinfo['usergroupid'] != 6) ? " WHERE cID <> 4 " : "";
$query = "SELECT * FROM " . TABLE_PREFIX . "vbtable " . $where . " ORDER BY dateline DESC";
?
Reply With Quote
  #3  
Old 11-23-2009, 01:30 AM
MyPornLife.info MyPornLife.info is offline
 
Join Date: Apr 2009
Posts: 40
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

ok. here is my mysql's table structure




i want to select rows from vbArticles
as im the admin my usergroup is 6
look at the table vbCat
cID-2 & 4 doesn't hav permission for usergroups-6

now look at table: vbArticles
row id-2,3,4,6 is under cID 2 & 4 (but see, i dont hav permission for them)
so they will be not selected
the query will select only others (id-1,5)

thats what i want
Reply With Quote
  #4  
Old 11-23-2009, 02:08 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That's pretty clear about what you need. What's the type of the cPermission field, is that a string with comma separated numbers?
Reply With Quote
  #5  
Old 11-23-2009, 04:16 AM
MyPornLife.info MyPornLife.info is offline
 
Join Date: Apr 2009
Posts: 40
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
That's pretty clear about what you need. What's the type of the cPermission field, is that a string with comma separated numbers?
no. VARCHAR.
why? shud i change it?
Reply With Quote
  #6  
Old 11-23-2009, 06:05 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by MyPornLife.info View Post
no. VARCHAR.
why? shud i change it?
No. I don't know. Just thinking about how to do the query. Try this:

Code:
$query = "SELECT * FROM " . TABLE_PREFIX . "vbarticles as vbarticles 
                 LEFT JOIN " . TABLE_PREFIX . "vbcat as vbcat ON vbarticles.cid = vbcat.cid
                 WHERE FIND_IN_SET(" . $vbulletin->userinfo['usergroupid'] . ", vbcat.cpermission) <> 0";
Reply With Quote
  #7  
Old 11-23-2009, 08:31 AM
MyPornLife.info MyPornLife.info is offline
 
Join Date: Apr 2009
Posts: 40
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

thank you very much
its working nice
Reply With Quote
Reply

Thread Tools
Display Modes

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:40 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.05213 seconds
  • Memory Usage 2,207KB
  • Queries Executed 13 (?)
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
  • (3)bbcode_code
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)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_postinfo_query
  • fetch_postinfo
  • 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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete