PDA

View Full Version : usergroup permission based SQL query


MyPornLife.info
11-22-2009, 10:47 PM
in a custom page...

i hav to use this: $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.

kh99
11-23-2009, 01:02 AM
I'm not sure if I understand what you're asking, but maybe something like (untested):

$where = ($vbulletin->userinfo['usergroupid'] != 6) ? " WHERE cID <> 4 " : "";
$query = "SELECT * FROM " . TABLE_PREFIX . "vbtable " . $where . " ORDER BY dateline DESC";

?

MyPornLife.info
11-23-2009, 01:30 AM
ok. here is my mysql's table structure

https://vborg.vbsupport.ru/external/2009/11/3.png


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

kh99
11-23-2009, 02:08 AM
That's pretty clear about what you need. What's the type of the cPermission field, is that a string with comma separated numbers?

MyPornLife.info
11-23-2009, 04:16 AM
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?

kh99
11-23-2009, 06:05 AM
no. VARCHAR.
why? shud i change it?

No. I don't know. Just thinking about how to do the query. Try this:

$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";

MyPornLife.info
11-23-2009, 08:31 AM
thank you very much :)
its working nice