Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Change div class value based on value in database

So I have data from $row[‘nomor’] and I converted it into progress bar with bootstrap. My questions is, can you make, if ‘nomor’ is fall under 40 (for example) it will change the div class to div class="progress-bar progress-bar-striped bg-danger", so based on bootstrap the bar will change its color to red, and soon.
Thanks for the answers.

<?php
$hasil=mysqli_query($mysqli,"SELECT * from test");               
$row=mysqli_fetch_array($hasil);
?>
<tr>
<td><a href="pages/examples/invoice.html"><?php echo $row['nama']; ?></a></td>
<td><?php echo $row['nomor']; ?></td>
<td><span class="badge rounded-pill bg-danger">Realisasi</span></td>
<td><div class="progress progress-sm">
<div class="progress-bar progress-bar-striped bg-success progress-bar-animated" role="progressbar" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100" style="width: <?php echo $row['nomor']; ?>%"><?php echo $row['nomor']; ?>%</div></div></td>
</tr>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can do something like this.

<?php
$hasil=mysqli_query($mysqli,"SELECT * from test");               
$row=mysqli_fetch_array($hasil);

$progressBarClass = "bg-danger";

if ($row['nomor'] < 40){
  $progressBarClass = "bg-warning";
}
elseif($row['nomor'] < 80){
   $progressBarClass = "bg-primary";
}
else{
   $progressBarClass = "bg-success";
}
?>
<tr>
    <td><a href="pages/examples/invoice.html"><?php echo $row['nama']; ?></a></td>
    <td><?php echo $row['nomor']; ?></td>
    <td><span class="badge rounded-pill bg-danger">Realisasi</span></td>
    <td><div class="progress progress-sm">
        <div class="progress-bar progress-bar-striped <?php echo($progressBarClass); ?> progress-bar-animated" role="progressbar" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100" style="width: <?php echo $row['nomor']; ?>%"><?php echo $row['nomor']; ?>%</div></div></td>
</tr>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading