0

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

Edited by reco21: n/a

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by simplypixie
0

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).

Edited by simplypixie: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.