SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2007
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    a question for class="" increment with php and html

    Greetings ,
    i want to do the next thing
    want to increment the class in html div tag , the element must generate 10 classes with different names . Ex:div1,div2,div3...etc . for use in css style element .
    <div class="div0"></div>.
    i have the fallowing php code for <div class="div0"></div>
    Code:
    for($j=0;$j<11;$j++)
      {
        echo "<div class=''>a</div>";
      }
    the class remains constant .
    after this
    Code:
    $n=0;
    function incr()
    {
    for ($i=0;$i<10;$i++)
    {
    echo $n++."<br />";
    }
    }
    then placing incr() in class echo "<div class=div".incr()."></div>
    the class remains constant
    any help ?

  2. #2
    code ninja hamstu's Avatar
    Join Date
    Nov 2002
    Location
    Montréal, Canada
    Posts
    375
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just do it all in the for loop.
    PHP Code:
    for ($i=0$i 10$i++)
    {
        echo 
    "<div class='div$i'>My Div</div>";



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •