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



  • 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 } ?>
    


  • Reverse the order and add a logic to delete from the first record that will become easier:

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

    echo $row['username'];

    $first = false;
    }

    Other details do not use functions http://php.net/manual/en/ref.mysql.php they are obsolete since version 5.5 and removed in PHP 7. Use http://php.net/manual/en/class.mysqli.php or http://php.net/manual/en/class.pdo.php




Suggested Topics