Hey. Im wondering how I would style the bottom row in a while loop. Can someone please help. How do I find the highest count and then if statement on my posts div.

<?php 
 $query="select * from posts order by id desc";
 $result = mysql_query($query); 
 $i = 0;
  
     while($row=mysql_fetch_array($result))
           {
             $i++;
             $id=$row['id'];
             $name=$row['name'];
	     $post=$row['post']; ?>  
           
    <div class="posts">
    <div class="numbered">#<?php echo $i; ?></div>
    <div class="postername"><?php echo $name ?></div>
    <div class="post"><?php echo $post; ?></div></div>
   
      <?php } ?>

Thanks

You could compare total number of results with your count increment in the while loop and use that:

<?php 
 $query="select * from posts order by id desc";
 $result = mysql_query($query); 
$numrows = mysql_num_rows($result);
 $i = 0;
  
     while($row=mysql_fetch_array($result))
           {
             $i++;
             $id=$row['id'];
             $name=$row['name'];
	     $post=$row['post']; 

             if ($i < $numrows) { $class = 'posts'; }
             else { $class = 'laspost'; }

             ?>  
           
    <div class="<?php echo $class; ?>">
    <div class="numbered">#<?php echo $i; ?></div>
    <div class="postername"><?php echo $name ?></div>
    <div class="post"><?php echo $post; ?></div></div>
   
      <?php } ?>

Or you could try using :last-child in your CSS (you may need a containing div as it will select the last child of the parent element).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.