Web Hosting Talk







View Full Version : Is this a valid Query?


gopper
11-24-2005, 03:58 PM
Hey guys, i was just trying to code a "FRIENDS" system kinda thing. So people can add other people as their frields, and if they have been approved kinda thing. it will list on the document.

Here is my query:SELECT * FROM profilefriends where reqid = $userid or reqerid = $userid AND active = '1'

IS THIS A CORRECT Query? .. Will this work?

HP-Jonathan
11-24-2005, 04:01 PM
Assuming $userid is being filled in before you pass it to mysql then it looks fine.

You can always just try it and see ;)

Dan L
11-24-2005, 04:03 PM
It doesn't make sense.

case 1: reqid = $userid
case 2: reqid = $userid & active = 1

either way, case 1 will be met, so you don't need the OR. :)

gopper
11-24-2005, 04:18 PM
Danx you misread it

Case1: reqid = $userid
Case2: reqerid = $userid

its basicaly, reqid is the user who wanted to be reqerid friend..
----------

This is what im wanting

Only export values where active = 1
Only export values of $userid is the same as reqid or reqerid

Is this the correct query..

(P.S. thanks for you quick respoces... this forum seems v-acctive)

dexxtreme
11-24-2005, 08:41 PM
As long as reqid and reqerid are numbers and not character or string fields, this should be the query you want:

SELECT * FROM profilefriends WHERE (reqid = $userid OR reqerid = $userid) AND active = '1'

mickd
11-25-2005, 04:42 AM
i would have the variables in quotes even if they are integers and if the value of the variables can be specified by the user, i would escape them too.

acidhoss
11-25-2005, 08:06 PM
are you using perl or PHP? If you're using perl, PLEASE use placeholders instead of nested variables...

siLentBASE
11-26-2005, 11:43 AM
If your variables are set correctly, yes the statement should work