Aureole Posted July 22, 2007 Share Posted July 22, 2007 The below is all fine and dandy and it works but I need more than one value for $allowed. I think I need to use an array but I'm new to PHP and haven't encountered an array before, searching Google yielded no results that helped. I just need $allowed to have more than one value. <?php $allowed = "5"; if ($member['id'] == $allowed) { echo "Show the code to add news stories..."; } else { echo "Show nothing..."; } ?> Link to comment https://forums.phpfreaks.com/topic/61245-solved-should-i-use-an-arrayor/ Share on other sites More sharing options...
cooldude832 Posted July 22, 2007 Share Posted July 22, 2007 yeah you could do $allowed = array("1","2","3","4","5",...); but i have a question for your uses, is allowed the UserID from the MySQL table and you have an allowed/disallowed users on a certain section? if so why not just add another field to the members table called security level and based on that integer value it determines if they can see certain content Link to comment https://forums.phpfreaks.com/topic/61245-solved-should-i-use-an-arrayor/#findComment-304709 Share on other sites More sharing options...
Aureole Posted July 22, 2007 Author Share Posted July 22, 2007 I'm using IPB SDK, I used get_advinfo which gives me... Array ( [id] => 1 [name] => no_comment [mgroup] => 4 [email] => [email protected] [joined] => 1052760073 [ip_address] => 80.129.253.245 [posts] => 7156 [title] => [allow_admin_mails] => [time_offset] => 1 [hide_email] => 0 [email_pm] => 0 [email_full] => [skin] => 12 [warn_level] => 0 [warn_lastwarn] => 0 [language] => 2 [last_post] => 1179530411 And a LOT more I could use the mgroup ( $member['mgroup'] ) instead I guess that would be better but still how would I do it? Link to comment https://forums.phpfreaks.com/topic/61245-solved-should-i-use-an-arrayor/#findComment-304712 Share on other sites More sharing options...
cooldude832 Posted July 22, 2007 Share Posted July 22, 2007 what is IPB SDK? Link to comment https://forums.phpfreaks.com/topic/61245-solved-should-i-use-an-arrayor/#findComment-304715 Share on other sites More sharing options...
Aureole Posted July 22, 2007 Author Share Posted July 22, 2007 Sigh..... Invision Power Board Site Development Kit..... But that doesn't matter, how can I do it whether I use id or mgroup or whatever it doesn't matter, how would I do it? ??? Link to comment https://forums.phpfreaks.com/topic/61245-solved-should-i-use-an-arrayor/#findComment-304717 Share on other sites More sharing options...
Aureole Posted July 22, 2007 Author Share Posted July 22, 2007 I tried using... <?php $allowed = array("1", "5"); if ($member['id'] == $allowed) { echo "<a href=\"news/submitnews.php\" title=\"Submit News\" class=\"newstitle\" onclick=\"return overlay(this, 'submitnews')\"> <img src=\"img/submit.png\" width=\"24px\" height=\"24px\" alt=\"Submit\" style=\"margin-right:5px;\" /></a>"; } else { echo ""; } ?> And me (id = 1) and my friend (id=5) cannot see the button to add news... Link to comment https://forums.phpfreaks.com/topic/61245-solved-should-i-use-an-arrayor/#findComment-304719 Share on other sites More sharing options...
cooldude832 Posted July 22, 2007 Share Posted July 22, 2007 that will work for a few uses, i'm not familiar with this software it probably should be a topic for third party script help, but i'd still say use a mysql field for security level (i'm assuming u have a mysql table for users) However if you use what you are doing now image doing it for 1000+ users Link to comment https://forums.phpfreaks.com/topic/61245-solved-should-i-use-an-arrayor/#findComment-304720 Share on other sites More sharing options...
Aureole Posted July 22, 2007 Author Share Posted July 22, 2007 Even if my Website grows and grows and we have thousands of users there will only be a few people who can add news, so it doesn't really matter...and the array() I tried didn't work and this shouldn't really be a topic for the third party script, if I was having problems with the script then maybe yes but I'm not I just didn't know hot to make $allowed have more than one value so... Link to comment https://forums.phpfreaks.com/topic/61245-solved-should-i-use-an-arrayor/#findComment-304723 Share on other sites More sharing options...
Aureole Posted July 22, 2007 Author Share Posted July 22, 2007 How come the array isn't working, If this worked before... <?php $allowed = "1"; if ($member['id'] == $allowed) { echo "<a href=\"news/submitnews.php\" title=\"Submit News\" class=\"newstitle\" onclick=\"return overlay(this, 'submitnews')\"> <img src=\"img/submit.png\" width=\"24px\" height=\"24px\" alt=\"Submit\" style=\"margin-right:5px;\" /></a>"; } else { echo ""; } ?> Then how come this doesn't... <?php $allowed = array('1', '5', '2', '3'); if ($member['id'] == $allowed) { echo "<a href=\"news/submitnews.php\" title=\"Submit News\" class=\"newstitle\" onclick=\"return overlay(this, 'submitnews')\"> <img src=\"img/submit.png\" width=\"24px\" height=\"24px\" alt=\"Submit\" style=\"margin-right:5px;\" /></a>"; } else { echo ""; } ?> Link to comment https://forums.phpfreaks.com/topic/61245-solved-should-i-use-an-arrayor/#findComment-304731 Share on other sites More sharing options...
trq Posted July 22, 2007 Share Posted July 22, 2007 Use... if (in_array($member['id'], $allowed)) { PS: Integers should not be surrounded by quotes. $allowed = array(1, 5, 2, 3); Link to comment https://forums.phpfreaks.com/topic/61245-solved-should-i-use-an-arrayor/#findComment-304732 Share on other sites More sharing options...
Aureole Posted July 22, 2007 Author Share Posted July 22, 2007 Thanks a lot, I was experimenting with in_array() but I couldn't get it to work. Link to comment https://forums.phpfreaks.com/topic/61245-solved-should-i-use-an-arrayor/#findComment-304740 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.