I’m building sorta primitive template system and putting some limitations
in the number of templates a certain user level can have access to.
So I have some code like this
if (is_premium($session_user_id)==true){
$userlevel = premium_level($session_user_id);
} else {
//if the user is not premium
$userlevel = 0;
}
then on the mysql I have:
SELECT FROM `galleries` where `UserLevel` = 0 and `UserLevel` ='".$userlevel."'
So any user with a userlevel higher than 0 will have access to all free user templates plus his user level templates. Hope you’re still clear as I’m not sure this is
the best way to do it but anyways.
So in either case the query will contain two values
The fist: UserLevel` = 0, will always be 0, and the second one may vary based on the userlevel but in cases the userlevel is 0 (free user) the query will excecute
like this:
SELECT FROM `galleries` where `UserLevel` = 0 and `UserLevel` =0
All I’m asking, is there any problem with this? Where userlevel=0 and userlevel=0 ?
I want to spare myself some time building a conditional query.
Thank you.
UPDATE:
So after your feedback I decided to make a conditional query. Thank you for your time.
Here’s how it looks like now:
if (is_premium($session_user_id)==true){
//Check premium accont level
$userlevel = premium_level($session_user_id);
$statement = "`galleries` where `UserLevel` = 0 OR `UserLevel` ='".$userlevel."' ";
} else {
//if the user is not premium
$userlevel = 0;
$statement = "`galleries` where `UserLevel` = 0";
}
I think it’s better this way.
You will get no results when both
UserLevelvalues aren’t the same. You should change theANDto beORso it will work.Instead use: