tags:

views:

29

answers:

4

How Not to Display a separator or a border after last data of the list?

I have a list of data which is coded in the form of <ul> and <li>

and it is formatted in the way that after every record a border or separator needs to be displayed but after last record this border should not be displayed.

I am aware of the fact that it has to be coded with the help of for loop, but I cannot catch the logic for that.

I am working in PHP and the data is being fetched from Mysql DB

below is the format of data to be displayed and in it, the last <li> is for displaying separator

UPDATED

for ($i=0, $n=sizeof($order->products); $i<$n; $i++) 
{
    <ul>
       <li class="col1"><?php echo $order->products[$i]['qty']; ?></li>
                        <li class="col2"><?php echo $product_image; ?></li>
                        <li class="col3"><?php echo $product_name; ?></li>
                        <li class="col4"><?php echo $currencies->display_price($finalprice, $order->products[$i]['tax'], $order->products[$i]['qty']); ?></li>

                        <li class="dotted-border"></li>
    </ul>  
}
+1  A: 

Unless I misunderstood it:

if($i<$n-1) echo"<li class="dotted-border"></li>";

Riho
EUREKA EUREKAAAAAA ;-) Thanks Mannn!!!! It worked......
OM The Eternity
A: 

a) either pack all strings in an array and the implode('<.. border ..>', $array) them

b) if ($numberOfCurrentItem < count($order->products)) { displayBorder(); }

cweiske
+2  A: 

You have an empty list item that's there for nothing but a border. Get rid of it. What you should be doing is putting a border at the top of every <ul> except the first one, and you can do that in CSS alone (without having to worry about putting presentation into your markup).

#parentContainer ul + ul {border-top: dotted black 1px;}

That being said, a more appropriate structure for what you are doing is a table rather than a list. You don't need to display it as a table, but that's exactly what it is from a semantic point of view.

Stan Rogers
+1 for CSS.....
Felix Kling
+1  A: 

The following should work:

<?php for ($i=0, $n=sizeof($order->products); $i<$n; $i++): ?> 
    <ul>
       <li class="col1"><?php echo $order->products[$i]['qty']; ?></li>
       <li class="col2"><?php echo $product_image; ?></li>
       <li class="col3"><?php echo $product_name; ?></li>
       <li class="col4"><?php echo $currencies->display_price(
         $finalprice, $order->products[$i]['tax'], 
         $order->products[$i]['qty']
       ); ?></li>
      <?php if($i == $n-1) ?>
        <li class="dotted-border"></li>
      <?php endif; ?>
    </ul>  
<?php endfor; ?>

However why dont you add the dotted-border class to the ul instead of having an empty element?

prodigitalson
U did a mistake buddy I recorrected it by <?php if($i < $n-1) ?>
OM The Eternity
+1 I appreciate that you gave me what I was looking for, Thank You
OM The Eternity