complicated nested loop php

Discussion in 'PHP' started by ironmankho, Sep 1, 2012.

  1. #1
    hi this is bit difficult to me do this i need idea how i can able to do in php how i can use loop to write this complicated nested loop php

    <tr>
    <td></td>
    <td></td>
    </tr>

    <tr class="alt">
    <td></td>
    <td></td>
    </tr>
     
    ironmankho, Sep 1, 2012 IP
  2. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #2
    Kind-of guessing at what you're asking, since that's not really 'complicated' -- and it's hard to say without the data.

    Are you just asking how to alternate the class on the TR? or how to populate those TD?

    What's the DATA? Without that we have no clue what you are looping (I almost asked "what loops?!?) or where... do you want to loop just the TR, the TR and the TD?
     
    deathshadow, Sep 1, 2012 IP
  3. greyinfotech

    greyinfotech Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    May be something link this

    
    
    for($i=0 ; $i < $cnt_tr ; $i++)
    {
        echo '<tr';
        if($class[$i]) echo ' class="'.$class[$i].'"';
        echo '>';
        
        for($j=0 ; $j < $cnt_td ; $j++)
        {
            echo '<td></td>';
        }
        
        echo '</tr>';
    }
    
    
    Code (markup):
     
    greyinfotech, Sep 18, 2012 IP
  4. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #4
    i think the ts ment something like this.

    
    $items = 100;
    for ($loops = 0; $loops < $items; $loops++)
    {
        echo '<tr' . (($loops % 2) ? ' class="odd"' : '') . '>';
        echo '<td>data1</td><td>data2</td>';
        echo '</tr>';
    }
    
    PHP:
    Yes?
     
    EricBruggema, Sep 18, 2012 IP