John Davidson

css - i want to change the background of the card div using PHP

0 comments
Message:


I used the for loop to get the data dynamically from the database and displayed ,Now I have to display those cards in different colors using Php No javascript is needed


<div class="row gutter-xs">
<?php
foreach($dispcnt as $object)
{
?><div class="col-xs-3 col-md-3">
<div class="card bg-info"> // card
<div class="card-values">
<div class="p-x">
<small><?php echo $object->qa;?> </small>
<h3 class="card-title-l"><?php echo $object->cnt;?> Counts</h3>
</div>
</div>
</div>
</div> // code of card ends here
<?php }?>
</div>

I want to change the color of the cards in PHP


I am excepting the cards to look like this



My Answer:
<div class="row gutter-xs">
<?php
$colors = array('bg-info', 'bg-success', 'bg-warning', 'bg-danger');
$color_index = 0;
foreach($dispcnt as $object)
{
?><div class="col-xs-3 col-md-3">
<div class="card <?php echo $colors[$color_index]; ?>"> // card
<div class="card-values">
<div class="p-x">
<small><?php echo $object->qa;?> </small>
<h3 class="card-title-l"><?php echo $object->cnt;?> Counts</h3>
</div>
</div>
</div>
</div> // code of card ends here
<?php
$color_index = ($color_index + 1) % count($colors);
}?>
</div>

Rate this post

5 of 5 based on 4016 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us