Hello everyone,

I have been trying to get this piece of coding to work! It contains multiple if statements and has just sent my mind spinning. I have an error code and cant seem to get past it!

What im trying to achieve is to basically check if the username is access level 1.

If the user is access level 1 then I want it to print the code and stop there!

If the user isnt access level 1 then I want it to go onto access level 2 and check is the user is level 2! If they are then it prints the code and if not then it checks to see if they are access level 3 and so on.

Its very complicated and has stumped me! The code is working ok at the moment but because my users can have multiple jobs and access levels the code basically checks for ALL jobs and then prints the code for each position that is true! This is obviously pointless and I want to make it so it only prints one copy of level 1 access if member is level 1 ...or to print ONLY one copy is member is level 2 access and so on.

Any Ideas?

while($row = mysql_fetch_array($find_access))
{
	//Show content for level ONE
	if ( ($row[lobby]== 1) AND ($row[user_id] == $username))
	{ 
		echo "show content gere for access level 1"; 
		$counter++;

//If no CONTENT for level ONE then show content for level TWO
	       	if ( !($row[lobby]== 1) AND ($row[user_id] == $username))
		      {
                                 //Show content for level TWO
                              	if ( ($row[lobby]== 2) AND ($row[user_id] == $username))
	                               { 
	                            	echo "show content gere for access level 2"; 
	                           	$counter++;
		                             }
		        }                     
		                           //If no CONTENT for level TWO then show content for level THREE
		                                          if ( !($row[lobby]== 2) AND ($row[user_id] == $username))
		                                          {
		                                                         //Show content for level THREE           
                                                          if ( ($row[lobby]== 3) AND ($row[user_id] == $username))
	                                                                          { 
	                                                                          echo "show content gere for access level 3"; 
	                           	                                             $counter++;
		                                                                         }
		                                          }
		                                               
		                                               
		                                              //If no CONTENT for level THREE then show content for level THREE
		                                          if ( !($row[lobby]== 3) AND ($row[user_id] == $username))
		                                          {
		                                                         //Show content for level FOUR           
                                                          if ( ($row[lobby]== 4) AND ($row[user_id] == $username))
	                                                                          { 
	                                                                          echo "show content gere for access level 4"; 
	                           	                                             $counter++;
		                                                                         }
		                                          }        
		                                          
		                                                                             //If no CONTENT for level FOUR then show content for level ZERO
		                                                                           if ( !($row[lobby]== 4) AND ($row[user_id] == $username))
		                                                                              {
		                                                                               //Show content for level FOUR           
                                                                                                if ( ($row[lobby]== 0) AND ($row[user_id] == $username))
	                                                                                                  { 
	                                                                                                echo "show content gere for access level 0"; 
	                           	                                                                   $counter++;
		                                                                                                 }
		                                                                                }        

		                                                               else
                                                                     	{
	                                                                 echo "<p><br><p><p><center>This page is a restrcited area. You do not have access!";
                                                                         }
	}

Ah ha ... I have just worked out what it was that was causing the error and it was the missing } from the while statement.

The problem I have now is I have 3 jobs assigned to my username.

If I select any one of these jobs to level 1 access then it works perfectly and shows level one access code.

However ... if I remove my level 1 access to one of level 2,3 or 0 then it just shows a blank page!

Any ideas why this is?

:O(

Thanks

Another problem I have found is if I set say 2 of my 3 jobs to level 1 then it obviously executes 2 copies of the level 1 access code!

Is there a way to limit this so it only shows 1 Copy? I have tried removing the $counter++; but that didnt work :>/

Please Help! lol

Hello again...

here is another thing ive tried to stop the multiple copies but it just shows an empty page!

$find_access =  mysql_query("SELECT user_id,lobby,shops FROM job_roles,job_positions WHERE job_roles.job_id = job_positions.id");


 
$find_job = fetch("SELECT * FROM job_positions WHERE name = '$find_access[job_id]'");
$counter = 0;
while($row = mysql_fetch_array($find_access))
{
	//Show content for level ONE
	if ( ($row[lobby]== 1) AND ($row[user_id] == $username))
	{ 
		$variable_one == 1;
		

//If no CONTENT for level ONE then show content for level TWO
	       	if ( !($row[lobby]== 1) AND ($row[user_id] == $username))
		      {
                                 //Show content for level TWO
                              	if ( ($row[lobby]== 2) AND ($row[user_id] == $username))
	                               { 
	                            	$variable_two == 1;
	                           	$counter++;
		                             }
		        }                     
		                           //If no CONTENT for level TWO then show content for level THREE
		                                          if ( !($row[lobby]== 2) AND ($row[user_id] == $username))
		                                          {
		                                                         //Show content for level THREE           
                                                          if ( ($row[lobby]== 3) AND ($row[user_id] == $username))
	                                                                          { 
	                                                                          $variable_three == 1;
	                           	                                             $counter++;
		                                                                         }
		                                          }
		                                               
		                                               
		                                              //If no CONTENT for level THREE then show content for level THREE
		                                          if ( !($row[lobby]== 3) AND ($row[user_id] == $username))
		                                          {
		                                                         //Show content for level FOUR           
                                                          if ( ($row[lobby]== 4) AND ($row[user_id] == $username))
	                                                                          { 
	                                                                          $variable_four == 1;
	                           	                                             $counter++;
		                                                                         }
		                                          }        
		                                          
		                                                                             //If no CONTENT for level FOUR then show content for level ZERO
		                                                                           if ( !($row[lobby]== 4) AND ($row[user_id] == $username))
		                                                                              {
		                                                                               //Show content for level FOUR           
                                                                                                if ( ($row[lobby]== 0) AND ($row[user_id] == $username))
	                                                                                                  { 
	                                                                                               $variable_zero == 1;
	                           	                                                                   $counter++;
		                                                                                                 }
		                                                                                }        

		                                                               else
                                                                     	{
	                                                                 $variable ="<p><br><p><p><center>This page is a restrcited area. You do not have access!";
                                                                         }
	}        
	
}                                                  


	if ($variable_one ==1)
	{ 
		$variable_one =" CODE FOR ACCESS LEVEL ONE HERE";
	} 
		if ($variable_two ==1)
	{ 
		$variable_two =" CODE FOR ACCESS LEVEL 2 HERE";
	} 
		if ($variable_three==1)
	{ 
		$variable_three=" CODE FOR ACCESS LEVEL 3 HERE";
	} 
		if ($variable_four==1)
	{ 
		$variable_four=" CODE FOR ACCESS LEVEL 4 HERE";
	} 
		if ($variable_zero==1)
	{ 
		$variable_zero=" CODE FOR ACCESS LEVEL 0 HERE";
	} 
echo <<<END

$openHTML

$variable_one
$variable_two
$variable_three
$variable_four
$variable_zero
$variable


$closeHTML

END;

ah nope wait a moment. Ive fixed the multiple copies of a particular level.

So for example if I have 2 level 1 positions it now only shows one copy of the level 1 access rights. :OD Whoohoo!

I just needed to set $variable_four == 1;
to $variable_four = 1;

So now thats one problem fixed. The only other proble is it will only show level one Access!

The IF statements muct be a bit dodgy!

:>/ Hmmm ...

Grrrrr ...

I was so close! This code is doing weird things I havent yet worked out. It will allow for access to level 1 and level 0 jobs and so I need to work out whats its doing!

Is anyone out there good with if statements?

I seem to be having an issue with the flow and order of it all. :O(

$find_job = fetch("SELECT * FROM job_positions WHERE name = '$find_access[job_id]'");
$counter = 0;
while($row = mysql_fetch_array($find_access))
{
	//Show content for level ONE
	if ( ($row[lobby]== 1) AND ($row[user_id] == $username))
	{ 
		$variable1 = 1;
		
   }
   

  //If no CONTENT for level ONE then show content for level TWO
  if ( ($row[user_id] == $username) AND  (!$row[lobby]== 1) AND ($row[user_id] == $username) AND ($row[lobby]== 2) )
		      {
		      
		      
                               //Show content for level TWO
                              	if ( ($row[lobby]== 2) AND ($row[user_id] == $username))
	                               { 
	                            	$variable2 = 1;
	                           	 }
	                           	 
		        }         
		        
		        
		        
		                    
		                           //If no CONTENT for level TWO then show content for level THREE
  if (  ($row[user_id] == $username) AND (!$row[lobby]== 1) AND (!$row[lobby]== 2) AND ($row[user_id] == $username) AND ($row[lobby]== 3))
		   {
		                               //Show content for level THREE           
                                    if ( ($row[lobby]== 3) AND ($row[user_id] == $username))
	                                    { 
	                                        $variable3 = 1;
	                           	                                           
		                                  }
		  }
		  
		  
		  
		  
		                                               
		                                               
  //If no CONTENT for level THREE then show content for level THREE
 if (  ($row[user_id] == $username) AND (!$row[lobby]== 1) AND (!$row[lobby]== 2) AND (!$row[lobby]== 3) AND ($row[user_id] == $username) AND ($row[lobby]== 4))
		   {
		                                  //Show content for level FOUR           
                                         if ( ($row[lobby]== 4) AND ($row[user_id] == $username))
	                                     { 
	                                     $variable4 = 1;
	                           	                                            
		                                  }
		    }        
		    
		    
		    
		    
		    
		                                          
 //If no CONTENT for level FOUR then show content for level ZERO
 if (  ($row[user_id] == $username) AND (!$row[lobby]== 1) AND (!$row[lobby]== 2) AND (!$row[lobby]== 3) AND(!$row[lobby]== 4) AND ($row[lobby]== 0))
		 {
		  //Show content for level FOUR           
        if ( ($row[lobby]== 0) AND ($row[user_id] == $username))
	               { 
	                $variable0 = 1;
	                           	                                                                 
		             }

		      } 

		  else
       {
	     $variable ="<p><br><p><p><center>This page is a restrcited area. You do not have access!";
        }
 
	
}                                                  


	if ($variable1 ==1)
	{ 
		$variable =" CODE FOR ACCESS LEVEL ONE HERE";
	} 
		if ($variable2 ==1)
	{ 
		$variable =" CODE FOR ACCESS LEVEL 2 HERE";
	} 
		if ($variable3==1)
	{ 
		$variable=" CODE FOR ACCESS LEVEL 3 HERE";
	} 
		if ($variable4==1)
	{ 
		$variable=" CODE FOR ACCESS LEVEL 4 HERE";
	} 
		if ($variable0==1)
	{ 
		$variable=" CODE FOR ACCESS LEVEL 0 HERE";
	} 
echo <<<END

$openHTML


$variable


$closeHTML

END;

Wow, ok. I've read your first few threads... but it still looks like you haven't fixed your fundamental error in any of your later posts.

Here's your code:

if (*user has level 1 job*){
    //level one code
    if (*user has level 2 job*){
        //level two code
        if (*user has level 3 job*){
            //level three code
        }
    }
}

Now if you follow this knowing that the the user only has a level 2 job they wont pass the first if statement so they skip all the code in the middle and never get to check if they have a level two job.

What your code should look like:

if (*user has level 1 job*){
    //level one code
} else {
    if (*user has level 2 job*){
        //level two code
    } else {
        if (*user has level 3 job*){
            //level three code
        } else {
            //"restricted page"
        }
    }
}

This checks if the user has a level one job and if they do the level one code shown then they skip the rest of the code. Only if the first check returns false is the level 2 check run.

So far as I know this is exactly what your looking for.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.