How to remove an "item" from the last record?

0

I need the last record not to show <div class="staffClearFix"></div>

<?php 
    $userdata = mysql_query("SELECT * FROM users WHERE rank = '9' AND status = 'Ativo' ORDER BY id");
    while($row = mysql_fetch_assoc($userdata)){
?>
    <?php echo $row['username']; ?>
    <div class="staffClearFix"></div>   
<?php } ?>
    
asked by anonymous 04.01.2018 / 14:17

1 answer

0

Invert the order and add a logic to delete from the first record that will be easier:

$first = true;
while($row = mysql_fetch_assoc($userdata)) {
   if (!$first) 
   {
       echo '<div class="staffClearFix"></div>';
   }

   echo $row['username'];

   $first = false;
}

Another detail, do not use functions mysql_* they are obsolete since version 5.5 and removed in the PHP 7. Use MySQLi or PDO

    
04.01.2018 / 14:50