在我的数据库中,列为status.By默认情况下,如果任何用户添加数据,它将被添加为0.如果我写入条件,则从数据库中获取数据时显示为空白。
如果status等于零,则应将文本显示为活动状态,如果status等于1,则应将文本显示为deactive。
这是我编写的代码,但它无效。
<table>
<thead>
<tr>
<th scope="col">S.No</th>
<th scope="col">Blog Title</th>
<th scope="col">Date</th>
<th scope="col">Hits</th>
<th scope="col" style="width: 65px;">Modify</th>
</tr>
</thead>
<tbody>
<?php $i = $this->uri->segment(3)+0; foreach ($records as $row){ $i++; ?>
<tr>
<td class="align-center"><?php echo $i;?></td>
<td><?php echo $row->blog_title;?></td>
<td><?php echo $row->date;?></td>
<td><?php echo $row->ne_views;?></td>
<td>
<a href="<?php echo site_url();?>/blogs/edit/<?php echo $row ->blog_id ;?>" class="table-icon edit" title="Edit"></a>
<a href="<?php echo site_url();?>/blogs/delete/<?php echo $row ->blog_id ;?>" onclick="return confirm('Are you sure to delete');" class="table-icon delete" title="Delete"></a>
<a class="button active" href="<?php echo site_url()?>/blogs/active/<?php echo $row ->blog_id ;?>"
<?php if($row->status==1){echo 'Deactive="Deactive"';} else{echo 'Active="Active"';}?>></a>
<a class="button preview" target="_blank" href="<?php echo site_url()?>/blogs/preview/<?php echo $row ->blog_id ;?>">Preview</a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
答案 0 :(得分:1)
试试这个
<a class="button" href="<?=site_url('blogs/').(($row->status==1)?'/delete/':'/active/').$row ->blog_id ;?>"> <?=($row->status==1)?'Active':'De-active';?></a>
如果状态为零,则url
处于非活动状态
如果状态为1,则url
处于活动状态