Reputation: 23
I want to show a status of active and inactive with php, and the value for active is 1 and for inactive is 0; How can i pu $status = ($row['is_active'])?'<span>Active</span>':'<span>Deactivited</span>';
variable in <td><?php echo $row->role; ?> <?php echo $status; ?></td>
here is my code
<?php
$status = ($row['is_active'])?'<span class="label label-success pull-right">Active</span>':'<span class="label label-danger pull-right">Deactivited</span>';
$no = 1;
$select = $pdo->prepare("SELECT * FROM user");
$select->execute();
while($row=$select->fetch(PDO::FETCH_OBJ)){
?>
<tr>
<td><?php echo $no++; ?></td>
<td><?php echo $row->username; ?></td>
<td><?php echo $row->fullname; ?></td>
<td><?php echo $row->role; ?> <?php echo $status; ?></td>
<td>
<a href="#"
onclick="return confirm('Delete User?')"
class="btn"</a>
</td>
</tr>
<?php
}
?>
Upvotes: 0
Views: 807
Reputation: 751
Just move the check for the $row['is_active']
into the for loop.
Here's an implementation.
<?php
$no = 1;
$select = $pdo->prepare("SELECT * FROM user");
$select->execute();
while ($row = $select->fetch(PDO::FETCH_OBJ)) {
$status = ($row->is_active) ? '<span class="label label-success pull-right">Active</span>' : '<span class="label label-danger pull-right">Deactivited</span>';
?>
<tr>
<td><?php echo $no++; ?></td>
<td><?php echo $row->username; ?></td>
<td><?php echo $row->fullname; ?></td>
<td><?php echo $row->role; ?><?php echo $status; ?></td>
<td>
<a href="#"
onclick="return confirm('Delete User?')"
class="btn"</a>
</td>
</tr>
<?php
}
?>
Upvotes: 2