1

I'm creating a site that lists custom userbars in a forum, and am using both PHP and SQL to achieve this easily. My question is: If a field is listed 'active' for the group, how do I go about adding a class specifically for that, to enable a glow around the Bootstrap card?

Here's my current code (forgive me if it's terrible)

     <div class="cards">
      <?php
      include_once("assets/php/db.php");
      $sql = "SELECT ubFilename, ubGroupName, ubGroupOwner, ubOwnerLink, isOfficial, isActiveGroup FROM UBSUserbars ORDER BY ubGroupName";
      $resultset = mysqli_query($conn, $sql) or die("database error:". mysqli_error($conn));      
      while( $record = mysqli_fetch_assoc($resultset) ) {
      ?>
      <div class="col-sm-4 col-card">
                <img src="i/OGUsers/<?php echo $record['ubFilename']; ?>">
                <hr>
                <h4 class="group"><?php echo $record['ubGroupName']; ?></h4>
                <span>Owner: <a class="owner" href="<?php echo $record['ubOwnerLink']; ?>"><?php echo $record['ubGroupOwner']; ?></a></span>
      </div>
      <?php } ?>
      </div>
cherry
  • 23
  • 4
  • It is a very bad idea to use `die(mysqli_error($conn));` in your code, because it could potentially leak sensitive information. See this post for more explanation: [mysqli or die, does it have to die?](https://stackoverflow.com/a/15320411/1839439) – Dharman Jan 16 '22 at 19:12

1 Answers1

0

You can use a ternary operator like this:

<div class="cards">
      <?php
      include_once("assets/php/db.php");
      $sql = "SELECT ubFilename, ubGroupName, ubGroupOwner, ubOwnerLink, isOfficial, isActiveGroup FROM UBSUserbars ORDER BY ubGroupName";
      $resultset = mysqli_query($conn, $sql);      
      while( $record = mysqli_fetch_assoc($resultset) ) {
      ?>
      <div class="col-sm-4 col-card <?php $record['isActiveGroup'] === 'yes' ? 'ADD-CLASS-HERE' : ''; ?>">
                <img src="i/OGUsers/<?php echo $record['ubFilename']; ?>">
                <hr>
                <h4 class="group"><?php echo $record['ubGroupName']; ?></h4>
                <span>Owner: <a class="owner" href="<?php echo $record['ubOwnerLink']; ?>"><?php echo $record['ubGroupOwner']; ?></a></span>
      </div>
      <?php } ?>
      </div>

You can change the value of 'yes' to the value of the active group that is saved on your database.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Paolo
  • 26
  • 2