Akenatehm Posted March 14, 2009 Share Posted March 14, 2009 Hey Guys, Just need to know if this is the right way to things: $getuserpriviliges = mysql_query("SELECT rank FROM users WHERE username = '$username'") or die(mysql_error()); if($getuserpriviliges == 'Owner' || 'Admin' || 'Owner/Admin' || 'Administrator') { //Execute this Code } Quote Link to comment https://forums.phpfreaks.com/topic/149446-solved-if-is-equal-to-or-or-or-help/ Share on other sites More sharing options...
Mchl Posted March 14, 2009 Share Posted March 14, 2009 It is not $result = mysql_query("SELECT rank FROM users WHERE username = '$username'") or die(mysql_error()); $row = mysql_fetch_array($result); $getuserpriviliges = $row['rank']; if($getuserpriviliges == 'Owner' || $getuserpriviliges =='Admin' || $getuserpriviliges =='Owner/Admin' || $getuserpriviliges =='Administrator') { //Execute this Code } alternatively if(in_array($getuserpriviliges, array("Owner","Admin","Owner/Admin","Administrator"))) { //Execute this Code } Quote Link to comment https://forums.phpfreaks.com/topic/149446-solved-if-is-equal-to-or-or-or-help/#findComment-784895 Share on other sites More sharing options...
trq Posted March 14, 2009 Share Posted March 14, 2009 Not at all. $getuserpriviliges is a result resource, not a string. Quote Link to comment https://forums.phpfreaks.com/topic/149446-solved-if-is-equal-to-or-or-or-help/#findComment-784896 Share on other sites More sharing options...
plutomed Posted March 14, 2009 Share Posted March 14, 2009 Try this: $getuserpriviliges = mysql_query("SELECT rank FROM users WHERE username = '$username'") or die(mysql_error()); if($getuserpriviliges == ('Owner' || 'Admin' || 'Owner/Admin' || 'Administrator')) { //Execute this Code } Quote Link to comment https://forums.phpfreaks.com/topic/149446-solved-if-is-equal-to-or-or-or-help/#findComment-784897 Share on other sites More sharing options...
Akenatehm Posted March 15, 2009 Author Share Posted March 15, 2009 Thanks plutomed. Works fine. Much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/149446-solved-if-is-equal-to-or-or-or-help/#findComment-784902 Share on other sites More sharing options...
plutomed Posted March 15, 2009 Share Posted March 15, 2009 No problem. Quote Link to comment https://forums.phpfreaks.com/topic/149446-solved-if-is-equal-to-or-or-or-help/#findComment-784905 Share on other sites More sharing options...
trq Posted March 15, 2009 Share Posted March 15, 2009 Thanks plutomed. Works fine. Much appreciated! That code will not work I'm afraid. read the previous replies. Quote Link to comment https://forums.phpfreaks.com/topic/149446-solved-if-is-equal-to-or-or-or-help/#findComment-784906 Share on other sites More sharing options...
PFMaBiSmAd Posted March 15, 2009 Share Posted March 15, 2009 I'll second that - You will find that only code similar to what Mchl posted will actually work because you need to fetch the row from the result set and reference the value that the query returned. The code you are apparently using will match anything as long as the query did not fail. Try it for an account that is not an 'Owner', 'Admin', 'Owner/Admin' or 'Administrator. Quote Link to comment https://forums.phpfreaks.com/topic/149446-solved-if-is-equal-to-or-or-or-help/#findComment-784910 Share on other sites More sharing options...
Akenatehm Posted March 15, 2009 Author Share Posted March 15, 2009 Thanks plutomed. Works fine. Much appreciated! That code will not work I'm afraid. read the previous replies. Ok, now they both are only showing Read More, even when I am logged in. How can I make it work? Quote Link to comment https://forums.phpfreaks.com/topic/149446-solved-if-is-equal-to-or-or-or-help/#findComment-784911 Share on other sites More sharing options...
trq Posted March 15, 2009 Share Posted March 15, 2009 Thanks plutomed. Works fine. Much appreciated! That code will not work I'm afraid. read the previous replies. Ok, now they both are only showing Read More, even when I am logged in. How can I make it work? Mchl posted an example several replies ago. Quote Link to comment https://forums.phpfreaks.com/topic/149446-solved-if-is-equal-to-or-or-or-help/#findComment-784912 Share on other sites More sharing options...
plutomed Posted March 15, 2009 Share Posted March 15, 2009 What code goes where it says: //Execute this code Quote Link to comment https://forums.phpfreaks.com/topic/149446-solved-if-is-equal-to-or-or-or-help/#findComment-784914 Share on other sites More sharing options...
trq Posted March 15, 2009 Share Posted March 15, 2009 What code goes where it says: //Execute this code Your code will not work so were not even at that part as yet. Quote Link to comment https://forums.phpfreaks.com/topic/149446-solved-if-is-equal-to-or-or-or-help/#findComment-784916 Share on other sites More sharing options...
Akenatehm Posted March 15, 2009 Author Share Posted March 15, 2009 Ok this is what I have: <?php $getuserpriviliges = mysql_query("SELECT rank FROM users WHERE username = '$username'") or die(mysql_error()); if(in_array($getuserpriviliges, array("Owner","Admin","Owner/Admin","Administrator"))) { echo '<a class="readmore"href=\"read_more.php?newsid=$id\">Read More</a>'; echo '<a class="readmore"href=\"edit_news.php?newsid=$id\">Edit</a>'; echo '<a class="readmore"href=\"edit_news.php?newsid=$id\">Delete</a></p> </div>'; } else { echo '<a class="readmore"href=\"read_more.php?newsid=$id\">Read More</a></p> </div>'; } } } ?> Mchls solution did not seem to work. Quote Link to comment https://forums.phpfreaks.com/topic/149446-solved-if-is-equal-to-or-or-or-help/#findComment-784917 Share on other sites More sharing options...
PFMaBiSmAd Posted March 15, 2009 Share Posted March 15, 2009 Go back and actually read all of his post until you understand what it is doing. Quote Link to comment https://forums.phpfreaks.com/topic/149446-solved-if-is-equal-to-or-or-or-help/#findComment-784920 Share on other sites More sharing options...
trq Posted March 15, 2009 Share Posted March 15, 2009 Your missing any call to mysql_fetch_assoc. As I said several replies ago, $getuserpriviliges is a result resource, now your treating it as an array. Theres a tutorial on our main site that covers basic database operations, you should read it. Quote Link to comment https://forums.phpfreaks.com/topic/149446-solved-if-is-equal-to-or-or-or-help/#findComment-784921 Share on other sites More sharing options...
plutomed Posted March 15, 2009 Share Posted March 15, 2009 ^^ He's got it. Quote Link to comment https://forums.phpfreaks.com/topic/149446-solved-if-is-equal-to-or-or-or-help/#findComment-784926 Share on other sites More sharing options...
Akenatehm Posted March 15, 2009 Author Share Posted March 15, 2009 Your missing any call to mysql_fetch_assoc. As I said several replies ago, $getuserpriviliges is a result resource, now your treating it as an array. Theres a tutorial on our main site that covers basic database operations, you should read it. I did have it in there. But I removed it because I thought it wasn't working (the real reason was because i didnt have my rank "Owner" in the Database). I added that all in and its all working fine. Thanks GUys. Quote Link to comment https://forums.phpfreaks.com/topic/149446-solved-if-is-equal-to-or-or-or-help/#findComment-784927 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.