如何在视图页面中检查会话ID和数据库ID

时间:2016-11-22 04:20:09

标签: php database codeigniter

在提示列表中,编辑按钮仅显示自己的提示

 <?php 
     $this->session->all_userdata();
     $id = $this->session->userdata('user_id');
     $data['user_id'] =  $id;
     $i=1;       
     foreach ($tips->result() as $row) 
     { ?>
         <tr>
             <td><?php echo $i++;?></td> 
             <td><?php echo $row->tips_desc;?></td>
             <td><?php if (isset($row->user_id)==='$id'){ ?> <a href="<?php echo site_url('index.php/Doctor/tips_update/'.$row->tips_id); ?>" ><span class="glyphicon glyphicon-pencil"style="color:green";></span></a><?php }else {echo"not";}?></td>      
  

1 个答案:

答案 0 :(得分:0)

关注您的代码,是建议:

<?php
if (isset($row->user_id)==='$id'){ ?> <a href="<?php echo site_url('index.php/Doctor/tips_update/'.$row->tips_id); ?>" ><span class="glyphicon glyphicon-pencil" style="color:green";></span></a><?php }else {echo"not";}?></td>

首先,isset()函数返回TRUEFALSE

1)您正在比较isset()为TRUE或FALSE与$ id

2)$id不应该有任何单引号,因为它不会评估。

所以,更正的声明:

<?php
if ($row->user_id === $id){
?>
<a href="<?php echo site_url('index.php/Doctor/tips_update/'.$row->tips_id); ?>">
    <span class="glyphicon glyphicon-pencil"style="color:green";></span>
</a>
<?php
}
else {
    echo "not";
}
?></td>