Forum Moderators: open

Message Too Old, No Replies

SQL Query

How would I got about writing this one

         

Jeigh

6:41 am on Jul 13, 2007 (gmt 0)

10+ Year Member



I'm working on a systemt to block users from doing a certain thing more than once, to do this I'm recording the users name that did it into the a column of the user they did it to.

For example John reccomends Fred, In Freds row under 'recusers' his name will be recorded in a format like this:

Fred - person1 - person2 - person3

I've got that working properly but this is what I want to do now. I'm checking the person whos trying to do it against the ones already there so if the query returns a name that is equal to the person that is doing it, it wont let them.

I guess I need to have somthing like:

SELECT recusers FROM users WHERE username='$username'

But I don't know how to just extract the one name I was looking for (which will be $vusername) instead of all the names in the recusers column.

Thanks.

phranque

7:07 am on Jul 13, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



i would recommend using another table to model the relationships between users.

otherwise, you don't need to extract the name - just to know that it exists in the string.
in that case you could try something like:

SELECT COUNT(*) as found FROM users WHERE username LIKE '% - $username%'

(as long as you don't allow hyphens in user names)

Jeigh

9:31 am on Jul 13, 2007 (gmt 0)

10+ Year Member



Thankyou for your help, I've found a solution using the explode function in PHP.