0
<?php
$get_user="SELECT privillage FROM admin_user WHERE id='".$_SESSION['user_id']."'";
 // echo $get_user;
 $exe_query=mysql_query($get_user);
$row=mysql_fetch_array($exe_query);
 $privillage_data = unserialize($row['privillage']); 
                  //print_r($privillage_data);
                  //$privillage_data1=explode(",",$privillage_data);
 echo '<pre>';
print_r($privillage_data);
$count=count($privillage_data);
 //echo "Count".$count;

 if($privillage_data[0] == '1' || $privillage_data[1] == '1' || $privillage_data[2] == '1' && $count >=1)
    {
        $priv_add ="true";
        echo "add--".$priv_add."</br>";
    }
else{$priv_add ="false";}

if($count >=2 && $privillage_data[1] == '2' || $privillage_data[0] == '2' || $privillage_data[2] == '2')
    {
        $priv_edit ="true";
        echo "edit--".$priv_edit."</br>";
    }
    else{$priv_edit ="false";}

    if($count ==3 && $privillage_data[2] == '3' || $privillage_data[0] == '3' || $privillage_data[1] == '3')
     {
        $priv_delete ="true";
        echo "delete--".$priv_delete."</br>";
    }
    else{$priv_delete ="false";}

?>

i'm getting undefined offset error in if condition,when using the above code!! how to solve the offset issue!! Need in help!!kindly make me simple

3
  • Then use isset to check it Commented Aug 12, 2014 at 6:12
  • where is the definition of your $privillage_data and $count ? Commented Aug 12, 2014 at 6:13
  • i tried isset()....i undefined issue went,but my expected result will not come Commented Aug 12, 2014 at 6:19

2 Answers 2

3

Looks like you have empty values for array index

try with isset() or empty() like

isset($privillage_data[0]) or !empty($privillage_data[0])

and so on... for all index

so your condition will be

if((!empty($privillage_data[0]) && $privillage_data[0] == '1') || (!empty($privillage_data[1]) && $privillage_data[1] == '1') || (!empty($privillage_data[2]) && $privillage_data[2] == '1') && $count >=1)

and so on for all conditions you are using

Sign up to request clarification or add additional context in comments.

3 Comments

if i add isset() means, i can overcome the error,but my privileges are not set for the corresponding user.
then you need to proper check your array values
@kiruthiga, what happens to $priv_add after it is set to true? Do you do something with that variable after all of the if statements?
1

Dump out the contents of privillage_data. There's an array key missing that you're expecting. Also, which line above is giving the error?

7 Comments

what do you mean by array key?
For example, $privillage_data[1]. That is expecting an array such as this array( 'a', 'b' ) with 'a' being at position 0 and 'b' being at position 1.
even though, i tried with "$privillage_data ==1" without or condition,the already set privileges are not working correctly
What does the "print_r($privillage_data);" display?
Array ( [0] => 1 )
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.