Assume that i have two strings like the following.
$sa = “12,20,45”; $sb = “13,20,50”;
I want to check whether any of the number in sa present in sb with back reference so that i can get those numbers back and do some calculation.
The numbers are nothing but unique id’s in database. So i am checking whether the ids in sa is present in the list of ids in sb.
Besides if it is possible to get all matching and non matching ids then that would be nice.
For this it doesn’t have to be one operation. Multiple operations is fine.(like executing match twice or more).
- What i am trying to do is i am creating subscribers and they are assigned to groups.
- I create newsletters and will assign to groups.
- If i try to assign a newsletter to the same group then i want the group id so that i can exempt that group and assign that newsletter to the rest.
- so if group 15,16,17 are already assigned with a newsletter and the next time i am trying to assign group 15,20,21 i want 15 to be exempted and i want the newsletter to be assigned to 20,21.
And… If i could get a mysql example too then that could be nice.
Any type of answer if it could help the please post it.
THX
first of all, this is not a problem you would want to solve with regex. At.all.
Second, you shouldn’t have a list of Ids as values in your database, especially if you need to look up on them. It’s inefficient and bad database design.
If you only require to link subscribers to newletters these would be the tables you need, one table per entity and a junction table for joining. I have left out the foreign key constraints.
If you would rather have your subscribers in a group and each subscriber can be in many groups, it would look like this.
Now your actions are rather simple. In your example we have newsletter 1, and we have groups 15, 16, 17, 20 and 21 and possibly other groups. We also have these values in NewslettersGroups
Now you want to connect newsletter 1 to 20 and 21 (only you think you need to do 15 as well). So just insert where it’s needed (I’m not 100% sure if this syntax works, I don’t use MySQL, but see this reference)