-1

I am trying to build a table that displays different information based on the permission level stored in SQL under the permissions column.

The website recieves all of the data it needs, and when I echo the data within the while loop it shows the correct data, but it seems like when I put the if and if else statements in it gets lazy and no matter what the value is it will execute the first if code.

I tried shuffling the if statements around so it tests if permissions=5 first but that just uses that code first.

I can't figure out what this could possibly be!! Any help would be greatly appreciated.

<? 
                      while($accountsRow = mysqli_fetch_array($accountsResult)){ 
                        $permissions = $accountsRow['permissions'];
                        echo $permissions;

                        if($permissions='2'){ 
                          echo "
                          <tr>
                            <td scope='row-sm' style='width: 30px'>
                                <h3><span class='badge civilNavy'>VENDOR</span></h3>
                            </td>
                            <td scope='row'>
                                <a>".$accountsRow['first']." ".$accountsRow['last']."</a>
                            </td>
                            <td>".$accountsRow['email']."</td>
                            <td>".$accountsRow['phone']."</td>
                            <td><a class='btn btn-sm btn-white text-dark' href='edit-account.php?accountID=".$accountsRow['accountID']."'><i class='fas fa-edit'></i></a></td>
                          </tr>"; 
                        } 
                        elseif($permissions='5'){ 
                          echo "
                            <tr>
                              <td scope='row-sm' style='width: 30px'>
                                  <h3><span class='badge civilRed'>ADMIN</span></h3>
                              </td>
                              <td scope='row'>
                                  <a>".$accountsRow['permissions']." ".$accountsRow['last']."</a>
                              </td>
                              <td>".$accountsRow['email']."</td>
                              <td>".$accountsRow['phone']."</td>
                              <td></td>
                            </tr>"; 
                        } 
                        elseif($permissions='1'){ 
                          echo "
                          <tr>
                            <td scope='row-sm' style='width: 30px'>
                                <h3>User</h3>
                            </td>
                            <td scope='row'>
                                <a>".$accountsRow['first']." ".$accountsRow['last']."</a>
                            </td>
                            <td>".$accountsRow['email']."</td>
                            <td>".$accountsRow['phone']."</td>
                            <td><a class='btn btn-sm btn-white text-dark' href='edit-account.php?accountID=".$accountsRow['accountID']."'><i class='fas fa-edit'></i></a></td>
                          </tr>"; 
                        } 
                        else{ 
                          echo "
                          <tr>
                            <td scope='row-sm' style='width: 30px'>
                                <h3></h3>
                            </td>
                            <td scope='row'>
                                <a>".$accountsRow['first']." ".$accountsRow['last']."</a>
                            </td>
                            <td>".$accountsRow['email']."</td>
                            <td>".$accountsRow['phone']."</td>
                            <td><a class='btn btn-sm btn-white text-dark' href='edit-account.php?accountID=".$accountsRow['accountID']."'><i class='fas fa-edit'></i></a></td>
                          </tr>"; 
                        } 
                      }?>
Dharman
  • 30,962
  • 25
  • 85
  • 135

1 Answers1

2

Use == instead of = in the if-clauses. = is assignment, == is comparison.

Paflow
  • 2,030
  • 3
  • 30
  • 50