Style the label in php - php

Scenario :
To Style label
Here is my code to view status
<?php
if ($shift['isActive'] == 1) {
echo 'Active';
} else {
echo 'Inactive';
}
?>
Problem :
Is there have any way to style the label Active & Inactive separately(background color).

Try This
if ($shift['isActive'] == 1) {
echo "<lable style='background-color: green;'>Active</lable>";
} else {
echo "<lable style='background-color: red;'>Inactive</lable>";
}

Use this code:
<div class="<?php $shift['isActive'] == 1 ? 'Active' : 'Inactive' ?>">
something
</div>

<label class="<?php if ($shift['isActive'] == 1) { echo 'Active'; } else {echo 'Inactive'; } ?>">
</label>

Related

PHP Else-if Statement For Routing to different page

In this code if $row['division'] is Leech it shows the link of related page. When $row['division'] is DME it's showing blank space and even it's not showing the last part of else statement.
<td>
<a rel="facebox"
<?php if ($row['division']=="Leech") { ?>
href="viewevaldme.php?evaid=<?php echo $row['evaid']; ?>" >
<?php } elseif ($row['division']=="DME") { ?>
href="vieweval.php?evaid=<?php echo $row['evaid']; ?> "
<?php } else { echo "Wrong Division Selected"; } ?>
Click Here
</a>
</td>
Try This :
<td>
<?php
if ($row['division'] == "Leech") {
echo '<a rel="facebox" href="viewevaldme.php?evaid='.$row['evaid'].'">Click Here</a>';
} elseif($row['division'] =="DME") {
echo '<a rel="facebox" href="vieweval.php?evaid='.$row['evaid'].'">Click Here</a> ';
} else {
echo 'Wrong Division Selected';
}
?>
</td>
Try this:
<td>
<?php
if ($row['division'] === "Leech") {
print '<a rel="facebox" href="viewevaldme.php?evaid='.$row['evaid'].'">Click Here</a>';
} elseif($row['division']==="DME") {
print '<a rel="facebox" href="vieweval.php?evaid='.$row['evaid'].'">Click Here</a> ';
} else {
print 'Wrong Division Selected';
}
?>
</td>

How can I add multiple onclick options on a div by using and if php statement?

I was thinking something like this would work, but it just uses the ('flipped') option regardless of the $comp_iteam variable.
<div class="flipper" id="kat" onclick= " <?php
if ($comp_iteam = 'heads') {
echo "this.classList.toggle('flipped')";
} else {
echo "this.classList.toggle('flippes')";
}
?>">
your code does not have correct syntax
you must replace
if ($comp_iteam = 'heads') {
with
if ($comp_iteam == 'heads') {
<div class="flipper" id="kat" onclick= " <?php
if ($comp_iteam == 'heads') {
echo "this.classList.toggle('flipped')";
} else {
echo "this.classList.toggle('flippes')";
}
?>">
whenever you assignig some value for variable you should use '=='
onclick= "<?php echo ($comp_iteam == 'heads') ? "this.classList.toggle('flipped')" : "this.classList.toggle('flippes')";?>"
I dont know whether its right or wrong please try this too bro
<div class="flipper" id="kat" onclick= " <?php
if ($comp_iteam == 'heads') {
echo "this.classList.toggle('flipped')"; } else {
echo "this.classList.toggle('flippes')";}
?>">

menu tab not becoming active in codeigniter

Here the menu tabs are not becoming and don't know why it seems look like this.Here is the control please have a look
public function vehicle($id=NULL)
{
if (!empty($id)) {
$data['active'] = 2;
$this->Vehicle_model->_table_name = "tbl_vehicles"; //table name
$this->Vehicle_model->_order_by = "id";
$data['vehicle_info'] = $this->Vehicle_model->get_by(array('id' => $id), TRUE);
} else {
$data['active'] = 1;
}
$data['all_vehicle_info'] = $this->Vehicle_model->view_vehicle(null,null);
$this->load->view('admin/vehicle/add_vehicle',$data);
}
here is the view
<ul class="tabs rs-tab">
<li class="<?php echo ($active == 1) ? "active" : ""; ?> tab col s3 "><a href="#manage" >All Vehicles</a></li>
<li class="<?php echo ($active == 2) ? "active" : ""; ?> tab col s3"><a href="#create" >New Vehicles</a></li>
</ul>
<div class="<?php echo ($active == 1) ? "active" : ""; ?>" id="manage" >
</div>
<div class="<?php echo ($active == 2) ? "active" : ""; ?>" id="create">
</div>

How do i set up an OR or || when using a ?: conditional statemetn

I have the below code which works perfectly. When the title is JohnPage, it does not display in the li.
<?php foreach($this->pages AS $page) { ?>
<li <?php echo $page['title'] == ('JohnPage') ? 'style="display:none";' : ''; ?>>
<a<?php echo ($page['active']?' class="active"':'');?> href="<?php echo $page['href'];?>"><?php echo $page['title'];?></a>
</li>
<?php } ?>
However, I want to say: if the title is either JohnPage or MyPage, do not display in the li. I tried the following:
<li <?php echo $page['title'] == ('JohnPage' OR 'MyPage') ? 'style="display:none";' : ''; ?>>
<li <?php echo $page['title'] == ('JohnPage' || 'MyPage') ? 'style="display:none";' : ''; ?>>
Neither works. Thanks for your help.
Instead of putting your conditional statements there. Try it this way.
<?php
foreach($this->pages AS $page) { ?>
<li <?php if($page['title'] == 'JohnPage' || $page['title'] == 'MyPage') { ?>style="display:none<?php } ?>">
<a <?php echo ($page['active']?' class="active"':'') ?> href="<?php echo $page['href'] ?>"><?php echo $page['title'] ?></a>
</li>
<?php
} // end foreach
?>

PHP spits actual HTML instead of image

Having a small issue here but cannot figure out where I have gone wrong. I have the following code which should show an image depending on the condition but instead it shows the HTML in the browser
if ($this->id_status == 2)
{
$this->id_status = "<img src='../_lib/img/gray_dot.png' />";
}
elseif ($this->id_status == 1)
{
$this->id_status = "<img src='../_lib/img/green_dot.png' />";
}
elseif ($this->id_status == 3)
{
$this->id_status = "<img src='../_lib/img/orange_dot.png' />";
}
Can anyone help?
try this:
<?php
if ($this->id_status == 2)
{
?>
<img src='../_lib/img/gray_dot.png' />
<?php
}
elseif ($this->id_status == 1)
{
?>
<img src='../_lib/img/green_dot.png' />
<?php
}
elseif ($this->id_status == 3)
{
?>
<img src='../_lib/img/orange_dot.png' />
<?php
}
?>

Categories