Rahul
Rahul

Reputation: 13

ol tag doesn't work while iterating li tag inside ol tag using for loop in php

I'm iterating li tag using for loop inside ol tag but the ordered list numbers for li tag are not displayed

Here is my code:

 <ol style="word-wrap:break-word;">
 <?php    
    for ($i = 0; $i < $length; $i++) {                                                                          
        echo '<li style="margin-left:0px;">'.$TnC1[$i].'</li>';                                             
       }
  ?>
</ol>

This is the result:

enter image description here

Upvotes: 1

Views: 543

Answers (2)

Nagama Inamdar
Nagama Inamdar

Reputation: 2857

You can try out following code snippet.

<ol style="word-wrap:break-word;">
 <?php    
    //Start the counter value from 1 instead of 0
    for ($i = 1; $i <= $length; $i++) 
    { 
     //Print the counter value                                                                         
     echo $i.".".$TnC1[$i];                                             
    }
  ?>
</ol>

Upvotes: 1

Sanjay Kumar N S
Sanjay Kumar N S

Reputation: 4739

Remove the unwanted ,(comma) in for loop and also put closing tag ''.

echo '<ol style="word-wrap:break-word;">';
for ($i = 0; $i < $length; $i++) { 

    echo '<li style="margin-left:0px;">'.$TnC1[$i].'</li>'; 

}
echo '</ol>'

Upvotes: 2

Related Questions