Jump to content

Recommended Posts

Hey i have a problem,
on my site i have a script called departments.php an example link to this script is departments.php?ID=24

the script checks if ID is a number and then runs the following query:

$query_RsDeptMembers = "SELECT * FROM vb3_user WHERE membergroupids LIKE '%{$dept_id}%')";

the column membergroupids is a comma seperated list of all of the usergroups this person is a member of.

now the query works fine, but if for example they was another member who was NOT in usergroup 24 so 24 would not be in the field membergroupids for him, but he was a member of usergroup 124, then he would be selected.

i did think about altering the query so it was like:
SELECT * FROM vb3_user WHERE membergroupids LIKE '%,{$dept_id},%')
But if ID is at the beginning then there would be no , at the beginning and if the ID was the last one in the list there would be no , at the end.

Is there another way i can search the membergroupids field to make sure that the number is there, and that it is not part of another number?
Link to comment
https://forums.phpfreaks.com/topic/14123-query-issue/
Share on other sites

You could ensure your lists of numbers  do have a "," at the beginning and end (,1,3,5,24,124,).

Better is not to store lists like that but store in a separate table

Group table :
[pre]
userid  groupid
  1      1
  1      3
  1      5
  1      24
  1    124[/pre]
Link to comment
https://forums.phpfreaks.com/topic/14123-query-issue/#findComment-55307
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.