2014-03-06 20 views
-2

如何使它像行中只有3個優惠現在我有一行,所有報價都在一行中我只想在tr和循環中顯示max 3 td。Table max 3​​在其他tr循環中

if(count($offer_list['item']) > 0) 
{ 
    $main_content .= '<table cellspacing="2" cellpadding="2" width=30>'; 
    foreach($offer_list['item'] as $item) 
    { 
    $main_content .= '<td class="shop"> 
    <a class="shop" style="display: block;" href="/shop/item/id/'.$item['id'].'"> 
    <center><img src="item_images/'.$item['item_id'].'.gif"><br><font color="white"><b>'.$item['name'].'</font></b><font color="red"> <b> '.$item['points'].' points</font></b>'; 
    if(!$logged) 
    { 
     $main_content .= '<p><b><a href="/account">[Login to buy]</a></b>'; 
    } 
    else 
    { 
     $main_content .= '<br><b><font size=1 color="white">Your points balance is: '.$user_premium_points; 
     $main_content .= '<br><font color="white"> <fieldset class="shop"><legend>DESCRIPTION</legend>'.$item['description'].'</fieldset></font><br><font color="white"><b> [Click to buy] </b></font></form> </a></center></td>'; 
    } 
    $main_content .= ''; 
    } 
    $main_content .= '</tr></table>'; 
} 

+3

[3店鋪優惠行中可能有重複](http://stackoverflow.com/questions/22236521/3-shop-offers-in-row) – djot

+0

如果您沒有得到任何問題的答案,請嘗試通過提供更多信息來改進它們,而不是再次發佈相同的問題! – djot

+0

我可以更多我認爲沒有更多intrested:S和我需要儘快解決這個問題 – Diverse

回答

0
$row_count = 1; 

$main_content .= '<table cellspacing="2" cellpadding="2" width=30>'; 
    foreach($offer_list['item'] as $item) { 

    // Check, if we are at position "1". If so, start new row 
    if ($row_count === 1) { $main_content .= '<tr>'; } 

    $main_content .= '<td class="shop"><a class="shop" style="display: block;" href="/shop/item/id/'.$item['id'].'"> 
    <center><img src="item_images/'.$item['item_id'].'.gif"><br><font color="white"><b>'.$item['name'].'</font></b><font color="red"> <b> '.$item['points'].' points</font></b>'; 
    if(!$logged) { 
     $main_content .= '<p><b><a href="/account">[Login to buy]</a></b>'; 
    } 
    else { 
     $main_content .= '<br><b><font size=1 color="white">Your points balance is: '.$user_premium_points; 
     $main_content .= '<br><font color="white"> <fieldset class="shop"><legend>DESCRIPTION</legend>'.$item['description'].'</fieldset></font><br><font color="white"><b> [Click to buy] </b></font></form> </a></center></td>'; 
    } 


    // Check, if we we are at position "3". If so, end row. (set position back to 1) 
    // Otherwise increase position with one level. 
    if ($row_count === 3) { 
     $row_count = 1; 
     $main_content .= '</tr>'; 
    } 
    else { 
     $row_count++; 
    } 
    } // end foreach 


// This is code for filling the "blank" table cells, if you don't have exactly some item count/3 = 0 
if ($row_count !== 3) { 
    for ($i=0; $i<=(3-$row_count); $i++) { 
    $main_content .= '<td>&nbsp;</td>'; 
    } 
    $main_content .= '</tr>'; 
} 
$main_content .= '</table>'; 

PS:<center>已被棄用以上說沒有有效的HTML了。

+0

希望你能設法接受這個解決方案! – djot

+0

我愛你:****** – Diverse