Jump to content

[SOLVED] Should I use an array...or...


Aureole

Recommended Posts

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

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

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?

 

 

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...

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

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...

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 "";
} ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.