Jump to content

Recommended Posts

Hi, This is a portion of the code I am working on:

 

if($access == 2)

 

{

 

    if ($permre['pages'] == indi_add)//

        {echo "show page";}

 

    if ($permre['pages'] == mass_add)//

        {echo "show page";}

 

    if ($permre['pages'] == export)//

        {echo "show page";}

 

}

 

elseif ($access == 0)

 

{

 

    if ($permre['pages'] == indi_add)//

        {echo "dont show page";}

 

    if ($permre['pages'] == mass_add)//

        {echo "dont show page";}

 

    if ($permre['pages'] == export)//

        {echo "dont show page";}**

 

}

I am creating a page where when a condition such as $access ==2 is executed it has multiple values. Some the values include: indi_add, mass_add and export. Then I want to use these values to create 3 conditions as shown above.

 

However, when executing this code, only the first if statement is being executed and the rest aren't. Is there a away where I can make php check the 3 if statements at once and do the action requested?...

 

Adding on, I cant use if(condition1 && condition2 && condition3) cause there is a possibility that one of the conditions may not be satisfied...

 

So how do I go about executing all the statements even if the first statement if true or false? Any valid suggestions will be a great help..Thank You..:D

 

Additional Notes: Sorry for the question being not very clear. I am actually getting the values such as indi_add, mass_add and export from phpmyadmin database. The query goes something like this: "select pages from access where access = 2". Due to the query above I get the page values which are the ones mentioned above. The echo page is just an example. In my actual coding, if the statement for access == 2 if true, the result is that a particular page will be activated. I am trying to do something like access control. Also, behind the scene, access level for each page can be changed by the admin. Therefore, the query above may bring different results everytime the access level changes...Hope this helps to make the question more clear...therefore, Im hoping to find a way where I can execute the if conditions whenever they r true....:D

Well for starters, only one of your if's are going to execute because you're checking the exact same array element against 3 different values. It can only be one, hence only one of those if statements will run.

 

If you want the possibility of all 3 running, then you will need to save the flag to allow it to be shown in a different array element, if that makes sense.

 

Do you understand what your code is actually saying now?

 

Denno

well...i did observe that only the first if statement is executing. May I know what you mean by saving the flag to allow it to be shown in different array elements?...Does it mean to create an array list?

Flag was a bad term..

 

What you should do is have two more array elements names pages2 and pages 3 (and rename the first to pages1 for consistency).

 

You will then have:

if ($permre['pages1'] == indi_add)// 
        {echo "show page";}

    if ($permre['pages2'] == mass_add)// 
        {echo "show page";}

    if ($permre['pages3'] == export)// 
        {echo "show page";}

 

Although on second thought, looking at that, you could just make them a boolean in your table, and check to see if it's a 1, in which case you would show the page... Example:

if ($permre['indi_add'] == 1)// 
        {echo "show page";}

    if ($permre['mass_add'])// 
        {echo "show page";}

    if ($permre['export'])// 
        {echo "show page";}

 

First thing you will notice is that in the second and third iff statements I've removed the '== 1'. If the result is only going to be a 1 or 0 (which is how you will set up your table), then if, for example, $permre['export'] == 0, then the if statement will read as:

if(0){
   echo "show page";
}

A 0 in the condition means false, so the code will not execute. It's up to you how you want to code it, you can leave the '== 1' in there so it's obvious to anyone reading your code exactly what you're doing.

 

So what you need to do with your table is to add 3 columns, with type ENUM, and options of '0','1'.

 

If I've missed the mark with what you actually want, let me know, otherwise I hope that helps you :).

 

Denno

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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