DIfferent class if first row

Eiffelmtl

New member
Hi,

I got a code who give class name different if rowid = 1, but if row('id') 1 is deleted the class is not appear.

I want the class use only on first row.

Here is my code

Code:
while($row = mysqli_fetch_array($result))
{ 
if ($row['id'] == '1'){
?>
<li><a id="<?php echo $row["urlName"] ?>Tab" class="active" href="#<?php echo $row["urlName"] ?>Content"><?php echo $row["title"] ?></a></li>
<?php } else {	?>
<li><a id="<?php echo $row["urlName"] ?>Tab" href="#<?php echo $row["urlName"] ?>Content"><?php echo $row["title"] ?></a></li>
} 
}

Any help will be useful.

Thanks
 
You need to count the cycles in the loop:
Code:
$i = 0;
while($row = mysqli_fetch_array($result))
{ 
    $className = $i === 0 ? 'first' : 'other';
    ?>
    <li>
        <a id="<?php echo $row["urlName"] ?>Tab" class="<?php echo $className; ?>" href="#<?php echo $row["urlName"] ?>Content">
            <?php echo $row["title"] ?>
        </a>
    </li>
    <?php
    $i++;
}
 
Back
Top